我在spring applicationContext.xml中配置了<!-- 配置事务管理器 -->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean> <tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="within(com.AAA.service.impl.*)" id="servicePointcut" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicePointcut" />
</aop:config>比如说 com.AAA.service.impl下的 addUser()方法下遍有2个user需要添加
就是 2个user有一个没有添加成功都失败,这样写配置就不对,这样是一条user添加成功就commit,
我想把整体addUser()做为一个事物来进行管理,请问我该怎么写?

解决方案 »

  1.   

    tx:method name="*" propagation="REQUIRED" />
    不妥 一般是这样吧 <tx:method name="*" read-only="true"/>只有配置的才有事务,其他都没有,要不然你是创建一个user时 掉用了com.AAA.service.impl.*)" 中其他方法就事务提交了
      

  2.   


    这样也就是说 如果com.AAA.service.impl里有个方法叫hello(),里边有增加,删除,这样他是怎么提交和回滚呢?...能加下您的qq么,问您几个问题么?
      

  3.   

    我也不是很懂啊 等下别误导你了 你用的oracle还是mysql