@Autowired
private GoodsDao dao;
@Transactional
public boolean save1(GoodsEntity entity){
//entity.setId(getStrId());
Object savepoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
dao.save(entity);
TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savepoint);
return true;
}
dao.save(entity);,,只有一个操作的话,,测试事务回滚,,,不合适吧,,,
在下面再放一个错误的操作 ,,看看上面这个能不能save
你的事务怎么配置的
你错误信息这样加试试 int a = 1/0;
<context:component-scan base-package="com.test.spring.mybatis" />
<!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<!-- <context:annotation-config /> --><!-- 手动注入的bean -->
<!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 可通过注解控制事务 -->
<!-- 自定义 事务方法 隔离级别 操作方式 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" isolation="REPEATABLE_READ" rollback-for="java.lang.Exception" propagation="REQUIRES_NEW"/>
<tx:method name="delete*" isolation="REPEATABLE_READ"/>
<tx:method name="update*" isolation="REPEATABLE_READ"/>
<tx:method name="*" read-only="true" isolation="REPEATABLE_READ"/>
</tx:attributes>
</tx:advice>
<!-- 具体services 事务配置 -->
<aop:config>
<aop:pointcut expression="execution(* com.test.spring.mybatis.services.*.*(..))" id="txMyPointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txMyPointcut"/>
</aop:config>
<tx:annotation-driven transaction-manager="transactionManager"/> 加这个
这些删了
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" isolation="REPEATABLE_READ" rollback-for="java.lang.Exception" propagation="REQUIRES_NEW"/>
<tx:method name="delete*" isolation="REPEATABLE_READ"/>
<tx:method name="update*" isolation="REPEATABLE_READ"/>
<tx:method name="*" read-only="true" isolation="REPEATABLE_READ"/>
</tx:attributes>
</tx:advice>