1.WEB-INF/lib 에 위치할 jar파일
Struts2관련
commons-fileupload.jar
commons-io.jar
freemarker.jar
ognl.jar
struts2-core.jar
xwork.jar
Spring관련
Struts2-spring-plugin.jar
Spring.jar
ibatis 및 DBCP, log4j, JSTL 기타등등
commons-dbcp.jar
commons-logging.jar
commons-pool.jar
ibatis.jar
log4j.jar
jstl.jar
standard.jar
sqljdbc.jar
commons-collection.jar
commons-lang.jar
2.web.xml
스트러츠2 관련
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
스프링 관련
<!--컨텍스트 로더 리스너에서 읽는 applicationContext 설정 파일 위치 지정-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext*.xml
</param-value>
</context-param>
<!--컨텍스트 로더 리스너 지정-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
3.applicationContext.xml
dtd 선언
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http:/www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
jdbc.property 파일 로딩(DB 접속 관련 정보)
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/config/jdbc.properties</value>
</list>
</property>
<property name="fileEncoding">
<value>UTF-8</value>
</property>
</bean>
<!--apache의 DBCP Connection Pool 사용-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--iBATIS SQLMaps의 설정 SqlMap setup for iBATIS Database Layer -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>WEB-INF/config/sqlmapConfig.xml</value>
</property>
<property name="dataSource" ref="dataSource"/>
</bean>
<!--Transaction manager for iBATIS Daos
DB연결에 관련된 설정을 DataSource 형태로 지정을 했기 때문에 Transaction 관리를 Spring의 DataSourceTransactionManager가 담당하도록 지정한다.-->
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<!-- Enable @Transactional support
Business Logic 클래스(여기서는 *ServiceImpl 클래스)에 어노테이션으로 한줄로 해결 할수 있다는데 확실히 아직 모르겠음. 그외 방법으로 Spring의 AOP, Advice를 이용 -->
<tx:annotation-driven transaction-manager="txManager"/>
4.sqlmapConfig.xml
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<!--
elecment XML 파일을 이용하여 build되는 다양한 옵션과 SQL Map Client instance를
최적화 하기 위한 설정들 이다.
setting element 와 모든 attributes는 모두 선택옵션이다.
-->
<sqlMapConfig>
<settings cacheModelsEnabled="true" classInfoCacheEnabled="true"
errorTracingEnabled="true" enhancementEnabled="true"
lazyLoadingEnabled="true" maxRequests="512"
maxSessions="128" maxTransactions="32"
useStatementNamespaces="true" />
<!- 해당 SQL문서 위치-à
<sqlMap resource="com/rainmac/dao/ibatis/board-dao.xml"/>
<sqlMap resource="com/rainmac/dao/ibatis/user-dao.xml"/>
<sqlMap resource="com/rainmac/dao/ibatis/attachFile-dao.xml"/>
</sqlMapConfig>
5.struts.xml
<struts>
<constant name="struts.objectFactory" value="spring" />
<package name="default" extends="struts-default" >
<action name="main" method="main" class="mainAction">
<result>/main.jsp</result>
<result name="input">/main.jsp</result>
</action>
</package>
<include file="/com/rainmac/action/user.xml" />
<include file="/com/rainmac/action/board.xml"/>
<include file="/com/rainmac/action/attachFile.xml"/>
</struts>
6.board.xml
<package name="board" namespace="/board" extends="struts-default">
<!-- Board -->
<action name="boardList" method="boardList" class="boardAction" >
<result name="success">/view/board/boardList.jsp</result>
<result name="input">/view/board/boardList.jsp</result>
</action>
<action name="boardUpdate" method="boardUpdate" class="boardAction">
<result type="chain" name="success">boardList</result>
</action>
</package>
7. applicationContext.xml
<bean id="boardService" class="com.rainmac.serviceImpl.BoardServiceImpl">
<property name="boardDao" ref="boardDao"/>
<property name="articleDao" ref="articleDao"/>
<property name="attachFileService" ref="attachFileService"/>
</bean>
<bean id="boardDao" class="com.rainmac.dao.ibatis.BoardDaoiBatis">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
<bean id="boardAction" class="com.rainmac.action.BoardAction" scope="prototype">
<property name="boardService" ref="boardService"/>
<property name="articleService" ref="articleService"/>
<property name="userService" ref="userService"/>
</bean>
8.BoardServiceImpl.java
public class BoardServiceImpl implements BoardService{
private BoardDao boardDao;
private AttachFileService attachFileService;
private ArticleDao articleDao;
public void setArticleDao(ArticleDao articleDao) {
this.articleDao = articleDao;
}
public void setAttachFileService(AttachFileService attachFileService) {
this.attachFileService = attachFileService;
}
public void setBoardDao(BoardDao boardDao) {
this.boardDao = boardDao;
}
public List getBoards() {
return boardDao.getBoards();
}
public Object getBoardInfo(HashMap<String, Object> map){
return boardDao.getBoardInfo(map);
}
}
9.흐름
*Action >> *Service(Interface) >> *ServiceImpl >> *DAO(Interface) >> *DaoiBatis
'IT > JAVA' 카테고리의 다른 글
Jcifs.jar (java) 네트워크 컴퓨터에 설치되어있는 프린터 목록을 보고 싶은가? 그렇다면 이 글을 보라. (0) | 2010.03.23 |
---|---|
스프링 정의할때 xml 스키마 모음 (0) | 2009.12.28 |
Java Web 개발자들을 위한 학습 로드맵 (0) | 2009.12.22 |
Java 도움되는 사이트(Site) 목록 (0) | 2009.12.21 |
Velocity error (0) | 2009.12.17 |