Spring Transaction:通过Template+Callback机制,实现对各种事务的统一封装。
<bean id="transactionManager" //对JDBC Transaction的封装
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="transactionManager" //对Hibernate事务的封装
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="transactionManager"//对JDO事务的封装
class="org.springframework.orm.jdo.JdoTransactionManager">
<property name="persistenceManagerFactory">
<ref bean="persistenceManagerFactory"/>
</property>
</bean>
<bean id="transactionManager" //对JTA 事务的封装
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName">
<value>java:/TransactionManager</value>
</property>
</bean>
<bean id="courseService"//利用AOP,将TransactionManager和普通的Service编织起来,实现事务。
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="proxyInterfaces">//编织后对外的接口
<list>
<value>com.springinaction.training.service.CourseService</value>
</list>
</property>
<property name="target">//目标
<ref bean="courseServiceTarget"/>
</property>
<property name="transactionManager">//植入的事务管理者
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributeSource">//事务的参数(隔离度,方法名等)
<ref bean="attributeSource"/>
</property>
</bean>