//struts2过滤器
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter spef;
//spring容器中对象出事化监听器
org.springframework.web.context.ContextLoaderListener cll;
//用来找寻action name对应在sping容器中的id别名类。
org.apache.struts2.spring.StrutsSpringObjectFactory ssf;
//驱动器管理类
org.springframework.jdbc.datasource.DriverManagerDataSource dm;
//session过滤器
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter osi;
//事物管理类
org.springframework.orm.hibernate3.HibernateTransactionManager ht;
//事物代理类
org.springframework.transaction.interceptor.TransactionProxyFactoryBean tp;
//过滤器关联spring类
org.springframework.web.filter.DelegatingFilterProxy df;
1.struts2过滤器
StrutsPrepareAndExecuteFilter oAndExecuteFilter;
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
<filter>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>StrutsPrepareAndExecuteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2.初始化监听器 (在web.xml)
ContextLoaderListener d;
org.springframework.web.context.ContextLoaderListener
<context-param>
<param-name>configLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
3.用来找寻action name对应在sping容器中的id别名类。
StrutsSpringObjectFactory j;
org.apache.struts2.spring.StrutsSpringObjectFactory
<constant name="struts.objectFactory"
value="org.apache.struts2.spring.StrutsSpringObjectFactory" /> 写在package标签的上面。
4.驱动器管理类
DriverManagerDataSource dataSource;
org.springframework.jdbc.datasource.DriverManagerDataSource
<!--数据源对象-->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
</property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="scott"></property>
<property name="password" value="sa"></property>
</bean>
5.session过滤器 需要写在struts2过滤器配置文件的前面。
<!--spring提供的管理session的 过滤器-->
OpenSessionInViewFilter o;
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
6.事务管理类:
HibernateTransactionManager h;
org.springframework.orm.hibernate3.HibernateTransactionManager
<!--事务管理-->
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
7.事物代理类
TransactionProxyFactoryBean
<!--事务模板对象 -->
<bean id="txTemplate"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<!-- 事务切面 -->
<property name="transactionManager" ref="hibernateTransactionManager" />
<!-- 事务属性配置-->
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
8.使过滤器路径与spring容器关联 习惯写在 1.struts2过滤器 后面
DelegatingFilterProxy dd;
org.springframework.web.filter.DelegatingFilterProxy
<filter>
<filter-name>indexFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>indexFilter</filter-name>
<url-pattern>/userindex.jsp</url-pattern>
</filter-mapping>