본문 바로가기
Spring

Spring-3.0.6 + Sitemesh-2.4.2 + myBatis-3.0.6 + urlrewrite-3.2.0

by 수앙 2011. 9. 10.

첫 번째로 필요한 라이브러리 가져오기
1. WEB-INF/lib 폴더에 넣음

aopalliance-1.0.jar

cglib-nodep-2.2.2.jar

commons-dbcp-1.3.jar

commons-dbutils-1.3.jar

commons-logging-1.1.1.jar

commons-pool-1.5.6.jar

freemarker.jar

jtds-1.2.jar

log4j-1.2.16.jar

mybatis-3.0.6-SNAPSHOT.jar

mybatis-spring-1.0.1.jar

org.springframework.aop-3.0.6.RELEASE.jar

org.springframework.asm-3.0.6.RELEASE.jar

org.springframework.aspects-3.0.6.RELEASE.jar

org.springframework.beans-3.0.6.RELEASE.jar

org.springframework.context-3.0.6.RELEASE.jar

org.springframework.context.support-3.0.6.RELEASE.jar

org.springframework.core-3.0.6.RELEASE.jar

org.springframework.expression-3.0.6.RELEASE.jar

org.springframework.instrument-3.0.6.RELEASE.jar

org.springframework.instrument.tomcat-3.0.6.RELEASE.jar

org.springframework.jdbc-3.0.6.RELEASE.jar

org.springframework.jms-3.0.6.RELEASE.jar

org.springframework.orm-3.0.6.RELEASE.jar

org.springframework.oxm-3.0.6.RELEASE.jar

org.springframework.test-3.0.6.RELEASE.jar

org.springframework.transaction-3.0.6.RELEASE.jar

org.springframework.web-3.0.6.RELEASE.jar

org.springframework.web.portlet-3.0.6.RELEASE.jar

org.springframework.web.servlet-3.0.6.RELEASE.jar

org.springframework.web.struts-3.0.6.RELEASE.jar

sitemesh-2.4.2.jar

sqljdbc.jar

urlrewrite-3.2.0.jar


두 번째로 WEB-INF 폴더 밑에 작성해야 할 파일
1. web.xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>INFO</param-value>
</init-param>
</filter>

<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher-servlet.xml</param-value>
</init-param>
</servlet>

<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>

2. sitemesh.xml
21번째 줄에
<param name="match.Mozilla [" value="ns" />
를 아래와 같이 바꿔준다.
<param name="match.Mozilla" value="ns" />
 
3. decorators.xml
<?xml version="1.0" encoding="UTF-8"?>
<decorators>

    <decorator name="layout" page="/template/common/layout/layout.ftl">
        <pattern>/*</pattern>
    </decorator>

</decorators>
 
4. urlrewrite.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>

<rule>
<from>^/([0-9]+)/([a-z]+)/([0-9]+)$</from>
<to>/$1/$2.do?order=$3</to>
</rule>

</urlrewrite>

세 번째로 src 폴더 밑에 작성해야 할 파일
1. applicationContext-jdbc.xml
SQL Server 2005 기준으로 DB 설정 함
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties" />
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${driverClassName}" />
<property name="url" value="${url}" />
<property name="username" value="${username}" />
<property name="password" value="${password}" />
<property name="initialSize" value="${initialSize}" />
<property name="maxActive" value="${maxActive}" />
<property name="maxIdle" value="${maxIdle}" />
<property name="maxWait" value="${maxWait}" />
<property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
    </bean>

</beans>
 
2. jdbc.properties
# common
driverClassName=net.sourceforge.jtds.jdbc.Driver
initialSize=20
maxActive=200
maxIdle=20
maxWait=30000
timeBetweenEvictionRunsMillis=60000

# url1
url=jdbc:jtds:sqlserver://localhost:1433/TEST
username=test
password=test

# url2
###

3. log4j.properties (log4j.xml 로 작성해도 상관없음)
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm} %-5p (%F:%L) - %m%n

log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=INFO
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG

log4j.logger.com.mybatis=DEBUG
 
4. mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

<settings>
<setting name="lazyLoadingEnabled" value="true" />
</settings>

<typeAliases>
<typeAlias alias="command" type="local.test.command.Command" />
</typeAliases>

</configuration>


각 설정에 대한 설명은 따로 하지 않음


끝.


'Spring' 카테고리의 다른 글

RestTemplate 사용법  (0) 2015.02.20
Spring quartz JMX 사용방법  (0) 2013.02.15
spring 2.5.x 컨트롤러 설명  (0) 2012.05.31
Spring-2.5.6 MVC  (0) 2011.10.22
스프링 어노테이션 관련 내용 (Spring Annotation)  (0) 2011.07.23

댓글