SSH中的Spring事务代理的常用的两种方法
这个配置文件是我做SSH的时候用的片断,用Spring来管理事务:
<!-- spring代理hibernate事务的两种方法 -->
<!-- 不管采用哪种方法 下面的这个bean都是必须的 -->
<bean id="transactionManager"
/>
</property>
</bean>
<!-- 1、spring事务代理模板 -->
<!-- 需要事务的Service类要继承下面的bean,使用方法如下-->
<!--
<bean id="txProxyTemplate" abstract="true"
singleton="false">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
<property name="classService">
<ref bean="ClassService" />
</property>
</bean>
<bean id="StudentServiceTarget"
singleton="false">
<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"
/>
</property>
<property name="transactionAttributeSource">
<ref bean="transactionAttributeSource" />
</property>
</bean>
<bean id="transactionAdvisor"
/>
</constructor-arg>
</bean>