SSH中的Spring事务代理的常用的两种方法
|
源代码网整理以下这个配置文件是我做SSH的时候用的片断,用Spring来管理事务: 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="del*">PROPAGATION_REQUIRED</prop> <prop key="change*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> 源代码网整理以下 </bean> 软件开发网 www.mscto.com <property name="studentDAO"> <ref bean="StudentDaoHibernate" /> </property> </bean> <bean id="StudentService" parent="txProxyTemplate"> <property name="target"> <ref bean="StudentServiceTarget"/> </property> </bean> --> <!-- 2、spring事务自动代理 --> <!-- 需要事务的方法只要方法名和下面的模式匹配就可以接受Spring的事务代理 --> <bean id="autoProxy" class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"> </bean> <bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource"> <property name="properties"> <props> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="del*">PROPAGATION_REQUIRED</prop> <prop key="change*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributeSource"> <ref bean="transactionAttributeSource" /> </property> </bean> <bean id="transactionAdvisor" class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> <constructor-arg> <ref bean="transactionInterceptor" /> </constructor-arg> 源代码网整理以下 </bean> 源代码网推荐 源代码网供稿. |
