使用spring的jdbc声明方式的事务管理。
在业务逻辑层接口PServices中定义三个方法如下:
interface PServices {
deploy();
regist();
add(); //数据入库
}
spring config文件如下:
<bean id="aDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- Connection Info -->
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${a.url}" />
<property name="username" value="${a.username}" />
<property name="password" value="${a.password}" />
</bean>
<bean id="aTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="aDataSource"></property>
</bean>
<aop:config>
<aop:advisor
pointcut="execution(* com.services.PServices.regist(..))"
advice-ref="aTxAdvice" /> <!--事务切入点为PServices接口的regist()方法-->
<aop:advisor>
<tx:advice id="aTxAdvice"
transaction-manager="aTransactionManager" >
<tx:attributes>
<tx:method name="get*" read-only= "true" />
<tx:method name="find*" read-only="true" />
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
我的调用关系是deploy方法调用regist()方法,regist()方法在调用add()方法,但是事务不生效!!!
在业务逻辑层接口PServices中定义三个方法如下:
interface PServices {
deploy();
regist();
add(); //数据入库
}
spring config文件如下:
<bean id="aDataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- Connection Info -->
<property name="driverClassName"
value="${jdbc.driverClassName}" />
<property name="url" value="${a.url}" />
<property name="username" value="${a.username}" />
<property name="password" value="${a.password}" />
</bean>
<bean id="aTransactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="aDataSource"></property>
</bean>
<aop:config>
<aop:advisor
pointcut="execution(* com.services.PServices.regist(..))"
advice-ref="aTxAdvice" /> <!--事务切入点为PServices接口的regist()方法-->
<aop:advisor>
<tx:advice id="aTxAdvice"
transaction-manager="aTransactionManager" >
<tx:attributes>
<tx:method name="get*" read-only= "true" />
<tx:method name="find*" read-only="true" />
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
我的调用关系是deploy方法调用regist()方法,regist()方法在调用add()方法,但是事务不生效!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货