首先,如果使用mysql,确定mysql为InnoDB类型。
事务管理的控制应该放到商业逻辑层。你可以写个处理商业逻辑的JavaBean,在该JavaBean中调用DAO,然后把该Bean的方法纳入spring的事务管理。
比如:xml文件定义如下:
<bean id="txProxyTemplate" 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="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="userManage" parent="txProxyTemplate">
<property name="target">
<bean class="com.ygw.spring.service.implement.UserManageImpl">
<property name="userDAO"><ref bean="userDAO"/></property>
</bean>
</property>
</bean>
com.ygw.spring.service.implement.UserManageImpl就是我们的实现商业逻辑的JavaBean。我们通过parent元素?/span>
事务管理的控制应该放到商业逻辑层。你可以写个处理商业逻辑的JavaBean,在该JavaBean中调用DAO,然后把该Bean的方法纳入spring的事务管理。
比如:xml文件定义如下:
<bean id="txProxyTemplate" 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="remove*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="userManage" parent="txProxyTemplate">
<property name="target">
<bean class="com.ygw.spring.service.implement.UserManageImpl">
<property name="userDAO"><ref bean="userDAO"/></property>
</bean>
</property>
</bean>
com.ygw.spring.service.implement.UserManageImpl就是我们的实现商业逻辑的JavaBean。我们通过parent元素?/span>
Spring事务管理配置
本文介绍如何在Spring框架中配置事务管理,重点放在如何将事务控制置于业务逻辑层,并通过具体的XML配置示例来说明如何设置不同的事务传播行为。
675

被折叠的 条评论
为什么被折叠?



