[출처] http://suicide102.egloos.com/2283394
1. web.xml 설정
: 아래의 설정은 spring과 iBatis의 연동과는 상관이 없는 설정내용입니다. 아래 설정은 WEB-INF/spring-config/ 에 있는 applicationContext로 시작하는 xml 파일을 웹어플리케이션이 시작될때 읽도록 하기 위해 설정하였습니다.(밑에 설명을 위해 참고로 설명)
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
...
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-config/applicationContext*.xml</param-value>
</context-param>
...
</web-app>
2. applicationContext.xml 설정
: spring 관련 설정들은 프로젝트의 규모에 따라 업무단위 또는 웹어플리케이션 계층(layer)단위로 나누기도 합니다. 나는 업무단위로 설정파일을 나누었으며, 일반적인 설정(dataSource,messageSource등)을 이 파일에서 설정하였습니다.
2.1. sqlMapClient 설정하기!
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
...
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/spring?characterEncoding=euckr"
p:username="javajigi" p:password="password" />
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:spring/mvc/sample/mapper/maps/sqlMapConfig.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
...
</beans>
3. sqlMapConfig.xml 설정
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- Optimizing Setting -->
<settings enhancementEnabled="true" useStatementNamespaces="true" />
<!-- Sql Map 설정 -->
<sqlMap resource="spring/mvc/sample/common/model/mapper/maps/sqlMap-Board.xml" />
</sqlMapConfig>
참고> settings의 요소
azyLoadingEnabaled | 적재지연은 정보를 필요한 때에만 읽어 들이고 다른 데이터는 명시적인 요청이 있을 때가지 적재를 미루는 기술이다. |
cacheModelsEnabled | 캐싱은 성능을 향상시키는 기법으로 최근 사용된 데이타가 미래에 다시 사용될 것이라고 가정하고 메모리에 계속저장해 두는 것 |
enhancementEnabled | 이 설정은 CGLIB에 최적화된 클래스를 통해 적재 지연 성능을 향상시킬지 여부를 지정 |참고| CGLIB는 실행시간에 코드를 생성하는 라이브러리이다. 다른 성능 향상 기법들 처럼 꼭 필요하다고 생각되지 않으면 사용하지 않는 것이 좋다. |
useStatementNameSpace | name space 사용 여부 |
maxRequest, maxSessions,maxTransactions | 사용하기를 권장하지 않는다. |
maxRequest | 이것은 한꺼번에 SQL문을 수행할 수 있는 쓰레드의 수. 셋팅값 보다 많은 쓰레드는 다른 쓰레드가 수행을 완료할때까지 블록된다. 다른 DBMS는 다른 제한을 가진다. 이것은 최소한 10개의 maxTransactions이고 언제나 maxSessions과 maxTransactions보다 크다. 종종 동시요청값의 최대치를 줄이면 성능향상을 보여준다. 예: maxRequests=”256” Default: 512 |
maxSessions | 이것은 주어진 시간동안 활성될수 있는 세션의 수이다. 세션은 명시적으로 주어질수도 있고 프로그램적으로 요청될수도 있고 쓰레드가 SqlMapClient 인스턴스를 사용할때마다 자동적으로 생성될수도 있다. 이것은 언제나 maxTransaction보다 같거나 커야 하고 maxRequests보다 작아야 한다. 동시세션값의 최대치를 줄이면 전체적인 메모리사용량을 줄일수 있다. 예: maxSessions=”64” Default: 128 |
maxTransactions | 이것은 한꺼번에 SqlMapClient.startTransaction()에 들어갈수 있는 쓰레드의 최대갯수이다. 셋팅값보다 많은 쓰레드는 다른 쓰레드가 나올때까지 블록된다. 다른 DBMS는 다른 제한을 가진다. 이 값은 언제나 maxSessions보다 작거나 같아야 하고 maxRequests보다 작아야 한다. 종종 동시트랜잭션의 최대치를 줄이면 성능향상을 보여준다. 예: maxTransactions=”16” Default: 32 |
4. sqlMap 예
<?xml version="1.0" encoding="EUC-KR" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Board">
<!-- DB 컬럼과 OBJECT 맵핑 -->
<resultMap id="boardList" class="spring.mvc.sample.board.model.Board">
<result property="boardNo" column="boardno" />
<result property="name" column="name" />
<result property="title" column="title" />
<result property="createDate" column="createDate" />
<result property="hitCount" column="hitCount" />
</resultMap>
<select id="list" resultMap="Board.boardList">
SELECT boardno, title, name, createdate, hitcount
FROM board
ORDER BY createdate DESC
</select>
</sqlMap>
5. 퍼시스턴스 계층(Persistence Layer)에서의 사용 예
...
public class IbatisWithMysqlBoardDAO extends SqlMapClientDaoSupport implements BoardDAO {
...
public List findBoardList(int currentPage, int countPerPage) throws DataAccessException,SQLException {
List result = null;
String sqlId = "Board.list";
SqlMapClient sqlMap = this.getSqlMapClient();
try{
result = sqlMap.queryForList(sqlId);
}catch(SQLException ex){
throw ex;
}
return result;
}
...
}
'Computer Science' 카테고리의 다른 글
kernel.org가 아닌 구글에서 안드로이드 소스 다운로드 및 빌드 (0) | 2011.11.07 |
---|---|
[알아봅시다] 샵 메일 (0) | 2011.11.06 |
스프링 - 아이바티스 연동 (0) | 2011.11.02 |
Spring 3 MVC 핼로 월드 예제 (0) | 2011.11.01 |
Spring DI(Dependency Injection)와 AOP(Aspect Oriented Programming) 맛보기 (0) | 2011.10.31 |