org.springframework.web.context.ContextLoaderListener;
org.springframework.web.context.ContextLoaderServlet;
org.springframework.web.struts.DelegatingActionProxy;
org.springframework.web.struts.ContextLoaderPlugIn;
org.apache.commons.dbcp.BasicDataSource;
org.springframework.orm.hibernate3.LocalSessionFactoryBean;
org.springframework.orm.hibernate3.HibernateTransactionManager;
org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator;
org.springframework.orm.hibernate3.HibernateInterceptor;
org.springframework.transaction.interceptor.TransactionInterceptor;
<!-- 添加spring插件到Struts-config.xml中,在struts中加载applicationContext.xml文件-->
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
<bean id="datasource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
</property>
<property name="url">
<value>jdbc:sqlserver://localhost:1433;dataBaseName=BBS</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value>accp</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
<property name="dataSource">
<ref bean="datasource" />
</property>
</bean>
<!-- 事务管理器-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="DAOBeanNameAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Impl,*Service</value>
</property>
<property name="interceptorNames">
<list>
<value>DAOInterceptor</value>
<value>hibernateInterceptor</value>
</list>
</property>
</bean>
<!-- 自动代理生成结束-->
<!-- aop拦截取代template-->
<bean id="hibernateInterceptor"
class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- aop拦截取代template结束-->
<bean id="DAOInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
事务或者采用
<bean id="BasicTransactionProxy" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
策略
<property name="transactionAttributes">
<props>
这里的方法签名可以精确到方法
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="do*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
业务代理类
<bean id="UserImplProxy" parent="BasicTransactionProxy">
<property name="target">
<ref bean="UserImpl"/>
</property>
</bean>