asm-1.5.3.jar
cglib-2.1_3.jar
commons-beanutils-1.8.0.jar
commons-collections-3.2.1.jar
commons-dbcp-1.3.jar
commons-digester-2.0.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
commons-pool-1.5.5.jar
dynamic-tiles2-1.1.jar
h2-1.2.142.jar
jackson-core-lgpl-1.6.0.jar
jackson-mapper-lgpl-1.6.0.jar
jstl-api-1.2.jar
log4j-1.2.13.jar
log4jdbc3-1.1.jar
mybatis-3.0.2.jar
mybatis-spring-1.0.0-RC1.jar
org.springframework.asm-3.0.4.RELEASE.jar
org.springframework.beans-3.0.4.RELEASE.jar
org.springframework.context.support-3.0.4.RELEASE.jar
org.springframework.context-3.0.4.RELEASE.jar
org.springframework.core-3.0.4.RELEASE.jar
org.springframework.expression-3.0.4.RELEASE.jar
org.springframework.jdbc-3.0.4.RELEASE.jar
org.springframework.transaction-3.0.4.RELEASE.jar
org.springframework.web.servlet-3.0.4.RELEASE.jar
org.springframework.web-3.0.4.RELEASE.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
기본적으로 위와 같은 라이브라리가 사용된다.
아직은 spring 3 가 mybatis 3 를 정식 지원하지는 않는다. 그래서 RC1 이 사용되었다. ( mybatis-spring-1.0.0-RC1.jar )
기본 구성을 해본 후 느낀 바는 spring 2.x + ibatis 2.x + tiles 를 구성했을시 개발자가 느끼는 장점? 은..
크게는 없다. 이전 spring 2.x 에서 일단 걸리적 거리는 것은 인터셉터 부분이었는데.. 모두들 커스터마이징 해서
잘들 사용하고 있더군.. (필자는 annoation 을 사용하고 일부 클래스를 커스터마이징 해서 사용했다. )
i18n 과 관련한 tag 는 역시나 만들어서 사용하는 편이 좀더 아름다워질듯 하다.
----------------------------------------------------------------------------------------------
web.xml
<!-- Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:test/spring.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
고전적인 방법이지만, Spring을 Root Context 와 나누는 방법은 여전히 효과적인 방법인듯 하다.
그래서 applicationContext.xml 와 웹MVC를 표현한 spring.xml 을 나눈상태이다.
----------------------------------------------------------------------------------------
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config.properties"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:MapperConfig.xml" />
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
</beans>
이때 component-scan 을 Service 와 DAO 별로 로딩하는 것이 추가 되어야 한다.
현재는 예시로 들지 않았다.(이것은 작성하는 사람 맘이라서.. )
SqlSessionTemplate , SqlSessionFactoryBean 은 RC1 인 상태지만 내용을 봐서는 추후 크게 수정될 일은
없을듯 하다.
-------------------------------------------------------------------------------------------------------------------
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- annotation config & scan -->
<context:annotation-config />
<context:component-scan base-package="test">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<mvc:annotation-driven />
<mvc:view-controller path="/index.do" view-name="index" />
<mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
<mvc:interceptor>
<mvc:mapping path="/test/*.do" />
<bean class="test.TestInterceptor" />
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/test/*.json" />
<bean class="test.TestInterceptor2" />
</mvc:interceptor>
</mvc:interceptors>
<!-- convert request data -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="cacheSeconds" value="0" />
</bean>
<!-- tiles2 layout config -->
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>classpath:test/tiles2.xml</value>
</list>
</property>
</bean>
<!-- view name tanslator -->
<bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" />
<!-- view resolver -->
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="do" value="text/html" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!--
<bean id="tilesViewResolver" class="org.springbyexample.web.servlet.view.tiles2.TilesUrlBasedViewResolver">
<property name="viewClass" value="org.springbyexample.web.servlet.view.tiles2.DynamicTilesView" />
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="tilesDefinitionName" value="default" />
<property name="tilesBodyAttributeName" value="body" />
<property name="tilesDefinitionDelimiter" value="." />
</bean>
-->
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="prefixJson" value="false" />
</bean>
</list>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:test/test</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8"/>
<property name="cacheSeconds" value="1" /><
<property name="fallbackToSystemLocale" value="false" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
</beans>
2.X 와 크게 바뀐 부분은 ContentNegotiatingViewResolver 라는 부분이다. 이것만 해도 꾀 간략된
모습이다.
전에 tiles 와 연동하기 위해서는 DynamicTiles 라는 것을 사용했지만 (위에 주석으로 표현했다.)
현재는 필요 없게 되었다. 왜냐하는 tiles 2 에 와일드카드를 사용하기 때문이다.
또한 인터셉터도 mapping을 사용해서 필요한부분에 붇일 수 있게 되었다.
( Annotation 으로 지원해 주길 바랬지만 .. 이건 좀 아쉽긴 하다. )
JSON 출력도 꾀 편한 상황이 되었다. (Jackson JSON 은 Json-lib 와는 다르다. )
---------------------------------------------------------------------------------------------
MapperConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<properties resource="config.properties"/>
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="defaultStatementTimeout" value="25000"/>
</settings>
<!--
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</dataSource>
</environment>
</environments>
-->
<mappers>
<mapper resource="test/InTest.xml"/>
<mapper resource="test/InTest_kr.xml"/>
</mappers>
</configuration>
------------------------------------------------------------------------------------------------------------
tiles2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name=".default" template="/WEB-INF/jsp/template/layout.jsp">
<put-attribute name="title" value="테스트" />
<put-attribute name="header" value="/WEB-INF/jsp/template/header.jsp" />
<put-attribute name="left" value="/WEB-INF/jsp/template/left.jsp" />
<put-attribute name="body" value="/WEB-INF/jsp/template/body.jsp" />
<put-attribute name="footer" value="/WEB-INF/jsp/template/footer.jsp" />
</definition>
<definition name="index" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/index.jsp" />
</definition>
<definition name="*/*/*" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/{1}/{2}/{3}.jsp" />
</definition>
<definition name="*/*" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/{1}/{2}.jsp" />
</definition>
<definition name="*" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/{1}.jsp" />
</definition>
</tiles-definitions>
아래 3개가 와일드 카드를 사용한 모습이다. 이것으로 인해 더이상 2.x 대의 spring 설정은 필요 없게 되었다.
이것 빼고는 이전상황과 다른것이 별로 없다.
출처 : http://blog.naver.com/PostView.nhn?blogId=junsu60&logNo=80116427379
cglib-2.1_3.jar
commons-beanutils-1.8.0.jar
commons-collections-3.2.1.jar
commons-dbcp-1.3.jar
commons-digester-2.0.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
commons-pool-1.5.5.jar
dynamic-tiles2-1.1.jar
h2-1.2.142.jar
jackson-core-lgpl-1.6.0.jar
jackson-mapper-lgpl-1.6.0.jar
jstl-api-1.2.jar
log4j-1.2.13.jar
log4jdbc3-1.1.jar
mybatis-3.0.2.jar
mybatis-spring-1.0.0-RC1.jar
org.springframework.asm-3.0.4.RELEASE.jar
org.springframework.beans-3.0.4.RELEASE.jar
org.springframework.context.support-3.0.4.RELEASE.jar
org.springframework.context-3.0.4.RELEASE.jar
org.springframework.core-3.0.4.RELEASE.jar
org.springframework.expression-3.0.4.RELEASE.jar
org.springframework.jdbc-3.0.4.RELEASE.jar
org.springframework.transaction-3.0.4.RELEASE.jar
org.springframework.web.servlet-3.0.4.RELEASE.jar
org.springframework.web-3.0.4.RELEASE.jar
slf4j-api-1.5.8.jar
slf4j-log4j12-1.5.8.jar
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
기본적으로 위와 같은 라이브라리가 사용된다.
아직은 spring 3 가 mybatis 3 를 정식 지원하지는 않는다. 그래서 RC1 이 사용되었다. ( mybatis-spring-1.0.0-RC1.jar )
기본 구성을 해본 후 느낀 바는 spring 2.x + ibatis 2.x + tiles 를 구성했을시 개발자가 느끼는 장점? 은..
크게는 없다. 이전 spring 2.x 에서 일단 걸리적 거리는 것은 인터셉터 부분이었는데.. 모두들 커스터마이징 해서
잘들 사용하고 있더군.. (필자는 annoation 을 사용하고 일부 클래스를 커스터마이징 해서 사용했다. )
i18n 과 관련한 tag 는 역시나 만들어서 사용하는 편이 좀더 아름다워질듯 하다.
----------------------------------------------------------------------------------------------
web.xml
<!-- Spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:test/spring.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
고전적인 방법이지만, Spring을 Root Context 와 나누는 방법은 여전히 효과적인 방법인듯 하다.
그래서 applicationContext.xml 와 웹MVC를 표현한 spring.xml 을 나눈상태이다.
----------------------------------------------------------------------------------------
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config.properties"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:MapperConfig.xml" />
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory" />
</bean>
</beans>
이때 component-scan 을 Service 와 DAO 별로 로딩하는 것이 추가 되어야 한다.
현재는 예시로 들지 않았다.(이것은 작성하는 사람 맘이라서.. )
SqlSessionTemplate , SqlSessionFactoryBean 은 RC1 인 상태지만 내용을 봐서는 추후 크게 수정될 일은
없을듯 하다.
-------------------------------------------------------------------------------------------------------------------
spring.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<!-- annotation config & scan -->
<context:annotation-config />
<context:component-scan base-package="test">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<mvc:annotation-driven />
<mvc:view-controller path="/index.do" view-name="index" />
<mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"/>
</bean>
<mvc:interceptor>
<mvc:mapping path="/test/*.do" />
<bean class="test.TestInterceptor" />
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/test/*.json" />
<bean class="test.TestInterceptor2" />
</mvc:interceptor>
</mvc:interceptors>
<!-- convert request data -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="cacheSeconds" value="0" />
</bean>
<!-- tiles2 layout config -->
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>classpath:test/tiles2.xml</value>
</list>
</property>
</bean>
<!-- view name tanslator -->
<bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" />
<!-- view resolver -->
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="do" value="text/html" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!--
<bean id="tilesViewResolver" class="org.springbyexample.web.servlet.view.tiles2.TilesUrlBasedViewResolver">
<property name="viewClass" value="org.springbyexample.web.servlet.view.tiles2.DynamicTilesView" />
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
<property name="tilesDefinitionName" value="default" />
<property name="tilesBodyAttributeName" value="body" />
<property name="tilesDefinitionDelimiter" value="." />
</bean>
-->
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="prefixJson" value="false" />
</bean>
</list>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:test/test</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8"/>
<property name="cacheSeconds" value="1" /><
<property name="fallbackToSystemLocale" value="false" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
</beans>
2.X 와 크게 바뀐 부분은 ContentNegotiatingViewResolver 라는 부분이다. 이것만 해도 꾀 간략된
모습이다.
전에 tiles 와 연동하기 위해서는 DynamicTiles 라는 것을 사용했지만 (위에 주석으로 표현했다.)
현재는 필요 없게 되었다. 왜냐하는 tiles 2 에 와일드카드를 사용하기 때문이다.
또한 인터셉터도 mapping을 사용해서 필요한부분에 붇일 수 있게 되었다.
( Annotation 으로 지원해 주길 바랬지만 .. 이건 좀 아쉽긴 하다. )
JSON 출력도 꾀 편한 상황이 되었다. (Jackson JSON 은 Json-lib 와는 다르다. )
---------------------------------------------------------------------------------------------
MapperConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//ibatis.apache.org//DTD Config 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-config.dtd">
<configuration>
<properties resource="config.properties"/>
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="multipleResultSetsEnabled" value="true"/>
<setting name="useColumnLabel" value="true"/>
<setting name="defaultStatementTimeout" value="25000"/>
</settings>
<!--
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</dataSource>
</environment>
</environments>
-->
<mappers>
<mapper resource="test/InTest.xml"/>
<mapper resource="test/InTest_kr.xml"/>
</mappers>
</configuration>
------------------------------------------------------------------------------------------------------------
tiles2.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name=".default" template="/WEB-INF/jsp/template/layout.jsp">
<put-attribute name="title" value="테스트" />
<put-attribute name="header" value="/WEB-INF/jsp/template/header.jsp" />
<put-attribute name="left" value="/WEB-INF/jsp/template/left.jsp" />
<put-attribute name="body" value="/WEB-INF/jsp/template/body.jsp" />
<put-attribute name="footer" value="/WEB-INF/jsp/template/footer.jsp" />
</definition>
<definition name="index" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/index.jsp" />
</definition>
<definition name="*/*/*" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/{1}/{2}/{3}.jsp" />
</definition>
<definition name="*/*" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/{1}/{2}.jsp" />
</definition>
<definition name="*" extends=".default">
<put-attribute name="body" value="/WEB-INF/jsp/{1}.jsp" />
</definition>
</tiles-definitions>
아래 3개가 와일드 카드를 사용한 모습이다. 이것으로 인해 더이상 2.x 대의 spring 설정은 필요 없게 되었다.
이것 빼고는 이전상황과 다른것이 별로 없다.
출처 : http://blog.naver.com/PostView.nhn?blogId=junsu60&logNo=80116427379
'Jsp-Servlet' 카테고리의 다른 글
api doc (0) | 2011.08.31 |
---|