struts 2+hibernate+spring 2.5 propertiesで統合配置方法を統合します.


struts 2+hibernate+spring 2.5 propertiesで統合配置方法を統合します.

           properties  hibernate.cfg.xml       ,       ,               .   SSH      jar       ,        :

1.    WEB.XML  
        <!-- spring    -->
 <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener> 
 <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>classpath*:applicationContext*.xml</param-value>
 </context-param>
   
   <!-- struts2    -->
 <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>

2.  struts2-spring-plugin-2.1.6.jar ,     struts+spring      
       ACTION    ,   struts.xml   :
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

3.   applicationContext.xml    :
  <beans>         
① <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       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.5.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

②   properties  :

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
   <value>classpath:system.properties</value>
  </property>
 </bean>

  : <value>    classpath:    ,            ,       SRC        
system.properties  .   properties          (          ):
#System Database Config
database.driverClassName=net.sourceforge.jtds.jdbc.Driver
database.connectionString=jdbc:jtds:sqlserver://10.1.0.6:1433/vendorDoc
database.username=sa
database.password=sql
hibernate.dialect=org.hibernate.dialect.SQLServerDialect

③   SESSIONFACTORY
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="mappingResources">
   <list>
    <value>cn/vendordoc/entity/DocRef.hbm.xml</value>
    <value>cn/vendordoc/entity/Staff.hbm.xml</value>
    <value>...</value>
   </list>
  </property>
  
  <property name="hibernateProperties">
   <props>
                            <prop key="hibernate.connection.driver_class">${database.driverClassName}</prop>
                             <prop key="hibernate.connection.url">${database.connectionString}</prop>
    <prop key="hibernate.connection.username">${database.username}</prop>
    <prop key="hibernate.connection.password">${database.password}</prop>

   <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">true</prop>
                           
   </props>
  </property>
 </bean> 

④       :

 <tx:advice id="txAdvice" transaction-manager="transactionManager">
     <tx:attributes>
      <!-- <tx:method name="execute*" propagation="REQUIRED"/> -->
      <tx:method name="*"  propagation="REQUIRED"/>
       </tx:attributes>
  </tx:advice>

<!--                -->
    <aop:config>
     <aop:pointcut id="allManagerMethod" expression="execution (* cn.test..*.*(..))"/>
     <aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
     
    </aop:config>
  : expression         cn.test                     ,            ,            cn.test.     ,          WEB              ,    SESSION   ,       ,  ,   lazy = false   ;  ,  web.xml   spring    
<!-- WEB     ,-->
<filter>
    <filter-name>hibernateFilter</filter-name>
    <filter-class>
     org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    </filter-class>
</filter>
<filter-mapping >
    <filter-name>hibernateFilter</filter-name>
 <url-pattern>/forum/*</url-pattern>
</filter-mapping>

4.     struts action  spring  ,          .
    spring  ,  applicationContext.xml       :
 <bean name="userAction" parent="baseAction" class="cn.vendor.web.action.UserAction" scope="prototype" >
 </bean>

   struts.xml   
<package name="user" extends="default" namespace="/user" >
  <action name="jumpLogin" class="userAction" method="loginView">
   <result>/WEB-INF/user/login.jsp</result>
  </action>
</package>

            .