以前项目中经常用spring事务处理还没有亲自配置过 惭愧现在马上上路.
首先在spring容器中配置transactionManager这个有好多实现这里以HibernateTransactionManager为例
<bean id=transactionManager class=orgspringframeworkormhibernateHibernateTransactionManager>
<property name=sessionFactory>
<ref local=sessionFactory />
</property>
</bean>
然后再定义一个事务模板
<bean id=txProxyTemplate abstract=true class=orgspringframeworktransactioninterceptorTransactionProxyFactoryBean>
<property name=transactionManager>
<ref bean=transactionManager />
</property>
<property name=transactionAttributes>
<props>
<prop key=save*>PROPAGATION_REQUIREDException</prop>
<prop key=remove*>PROPAGATION_REQUIREDException</prop>
<prop key=update*>PROPAGATION_REQUIREDException</prop>
<prop key=incress*>PROPAGATION_REQUIREDException</prop>
<prop key=*>PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
这个模板怎样应用到业务方法上呢?请看下面的配置
<!
<bean id=userService class=comsclschserviceimplUserServiceImpl>
<property name=userDao>
<ref bean=BmUserDAO />
</property>
</bean>
>
<! 为userService配置事务>
<bean id=userService parent=txProxyTemplate>
<property name=target>
<bean class=comsclschserviceimplUserServiceImpl>
<property name=userDao>
<ref bean=BmUserDAO />
</property>
</bean>
</property>
</bean>
注释部分是原来没有配置事务的service parent指定为这个service配置的事务模板.