在实际工作中Required是用的最多的!
最多不过有些查询需要用的Supports
我用aspectj写了一个Spring的声明式事物!当然Spring也有一个TransactionProxyFactory这样的配置可以简单实现声明事物!
以下的上传的代码是用来以后自己可以回忆用的!
主要的配置是:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation= "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"><aop:config> <aop:pointcut id="transMgr" expression="execution(@com.lovo.trans.Trans * *.*(..))"/> <aop:advisor pointcut-ref="transMgr" advice-ref="txManager"/></aop:config><tx:advice id="txManager" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="create*" propagation="REQUIRED" rollback-for="SQLException" /> <tx:method name="find*" propagation="SUPPORTS"/> </tx:attributes></tx:advice>
<!-- dataSource --><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="url"> <value>jdbc:oracle:thin:@localhost:1521:orcl</value> </property> <property name="defaultAutoCommit"> <value>false</value> </property> <property name="username"><value>scott</value></property> <property name="password"><value>wl</value></property> </bean>
<!-- 事物管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"> <ref local="dataSource"/> </property> </bean> <bean id="bookService1" class="com.lovo.trans.BookService"> <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="bs2"> <ref bean="bookService2"/> </property> </bean> <bean id="bookService2" class="com.lovo.trans.BookService2"> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean> </beans>
