spring 2.0 + hibenate 3.2 + struts 2.0 설정 기록

struts 2.0 + spring 2.0 + hibenate 3.2 결합 개발 웹 응용 프로그램 은 많은 개선 을 가 져 왔 습 니 다. 더 많은 것 은 설정 매개 변수 입 니 다. 아래 결합 개발 프로젝트 는 struts 2.0 + spring 2.0 + hibenate 3.2 를 어떻게 사용 하 는 지 설명 합 니 다.
데이터베이스 oracle 9i / 10g
패키지 구조
cn. nlinux. test. action 설치 struts 2.0 액 션
cn. nilnux. test. bo 배치 BO
cn. nlinux. test. bo. hbms 에 hibenate 3 데이터 시트 설정 파일 을 설치 합 니 다.
cn. nlinux. test. business PO 인터페이스
cn. nlinux. test. business. service PO 구현
cn. nlinux. test. dao DAO 인터페이스
cn. nlinux. test. dao. hibenate DAO 구현
applicationContext. xml 설정
이 파일 은 / 응용 디 렉 터 리 / WEB - INF / 아래 에 놓 여 있 습 니 다.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:lang="http://www.springframework.org/schema/lang"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName">
   <value>oracle.jdbc.driver.OracleDriver</value>
  </property>
  <property name="url">
   <value>jdbc:oracle:thin:@192.168.1.8:1521:test</value>
  </property>
  <property name="username">
   <value>risk</value>
  </property>
  <property name="password">
   <value>123456</value>
  </property>
  <property name="maxActive">
   <value>20</value>
  </property>
  <property name="maxIdle">
   <value>5</value>
  </property>
  <property name="maxWait">
   <value>-1</value>
  </property>
  <property name="defaultAutoCommit">
   <value>true</value>
  </property>
 </bean>

 <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor" /> 
 <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true"> 
  <property name="nativeJdbcExtractor"> 
   <ref bean="nativeJdbcExtractor" /> 
  </property> 
 </bean> 

 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref local="dataSource" />
  </property>  
  <property name="mappingDirectoryLocations">
   <list>
    <value>classpath:/cn/nlinux/test/bo/hbms</value>
   </list>
  </property>  
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
   </props>
  </property>
  <property name="lobHandler" ref="oracleLobHandler" />
 </bean>
 
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>

 <bean id="transactionInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <property name="transactionManager" ref="transactionManager"></property>
  <property name="transactionAttributes">
   <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="add*">PROPAGATION_REQUIRED</prop>
    <prop key="set*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="register">PROPAGATION_REQUIRED</prop>       
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="valid*">PROPAGATION_REQUIRED,readOnly</prop>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>

 <bean
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <property name="beanNames">
   <value>*Service</value>
  </property>
  <property name="interceptorNames">
   <value>transactionInterceptor</value>
  </property>
 </bean>

 <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
  <property name="transactionInterceptor" ref="transactionInterceptor">
  </property>
 </bean>

</beans>


dao. xml 파일, dao 설정 에 사용

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:lang="http://www.springframework.org/schema/lang"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd"
 default-autowire="byName"> 
 <bean id="employeeInfoDao" class="cn.nlinux.test.dao.hibernate.EmployeeInfoDao"/>
 <bean id="categoryInfoDao" class="cn.nlinux.test.dao.hibernate.CategoryInfoDao"/> 
 
</beans>


의뢰 파일 service. xml 설정

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:lang="http://www.springframework.org/schema/lang"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd"
 default-autowire="byName">
 <bean id="categoryService" class="cn.nlinux.test.business.service.CategoryService"/>
 <bean id="employeeService" class="cn.nlinux.test.business.service.EmployeeService"/>  
</beans> 


웹. xml 프로필

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <display-name>AllwapWeb</display-name>
 <distributable />
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml /WEB-INF/dao.xml /WEB-INF/service.xml</param-value>
 </context-param>
 <listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>
 <filter>
  <filter-name>struts</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  <init-param>
   <param-name>actionPackages</param-name>
   <param-value>cn.allwap.backend.action</param-value>
  </init-param>
 </filter>
 <servlet>
  <servlet-name>dwr</servlet-name>
  <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
  <init-param>
   <param-name>debug</param-name>
   <param-value>true</param-value>
  </init-param>
 </servlet> 
 <filter>
  <filter-name>openSession</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  <init-param>
   <param-name>singleSession</param-name>
   <param-value>false</param-value>
  </init-param>
 </filter>
 <filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
 </filter>
 <filter>
  <filter-name>encodingFilter</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-mapping>
  <filter-name>encodingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>openSession</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <servlet-mapping>
  <servlet-name>dwr</servlet-name>
  <url-pattern>/dwr/*</url-pattern>
 </servlet-mapping>
 <filter-mapping>
  <filter-name>struts-cleanup</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>struts</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>default.jsp</welcome-file>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>
</web-app>


struts 2.0 프로필
struts.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
 <constant name="struts.enable.DynamicMethodInvocation" value="false" />
 <constant name="struts.devMode" value="false" />
 <constant name="struts.serve.static" value="true" />
 <constant name="struts.serve.static.browserCache" value="false" /> 
 <constant name="struts.action.extension" value="do" />
 <constant name="struts.configuration.xml.reload" value="true" />
 <constant name="struts.continuations.package" value="cn.nlinux.test.action" />
 <constant name="struts.multipart.saveDir" value="/resources/tmp" />
 <constant name="struts.multipart.maxSize" value="51200000000" />
 <constant name="struts.objectFactory" value="spring" />
 <constant name="struts.locale" value="zh_CN" />
 <constant name="struts.i18n.encoding" value="utf-8" />
 <constant name="struts.custom.i18n.resources" value="ApplicationResources" />

    <include file="struts-test.xml" />
    
</struts>


좋은 웹페이지 즐겨찾기