1.出异常不回滚:
@Transactional 以aop形式对异常进行拦截, 该注解放在某方法上,只有从类的外部调用该方法的时候才能生效;(父子类之间也可以生效)
2.被@Transactional 修饰的类用@Autowired注入,找不到bean:
需要以接口的形式才能被正常注入。
如 :
@Autowired
private AInterface aInterface;(其中AInterfaceImpl 中用到了@Transactional )
原因,Transactional 默认使用jdk代理的方式,在jdk代理方式下,@Transactional标记的类需要实现接口,并通过接口去访问类中的方法。
3.datasource的@bean 外使用了@component, 导致每次执行sql都会获取 新的连接,新连接默认autocommit=true, 导致事务不能使用
内部带有@bean方法或属性的类应使用@configuration,而不是@component