Spring中 @Transactional 註解的限制
1. 同一個類中, 一個nan-transactional的方法去調用transactional的方法, 事務會失效html
If you use (default) Spring Proxy AOP, then all AOP functionality provided by Spring (like @Transational) will only be taken into account if the call goes through the proxy. -- This is normally the case if the annotated method is invoked from another bean. 若是使用(默認)Spring Proxy AOP,那麼Spring提供的全部AOP功能(如@Transational)只有在經過代理類調用時才被考慮。 - 若是從普通的bean調用註解方法,則一般註解是不會生效的。
When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods.
使用代理時,應將@Transactional註解應用於具備public方法。 若是使用@Transactional註解對protected,private或包訪問權限的方法進行修飾,儘管不會引起錯誤,可是帶註解的方法不會顯示配置的事務設置。 若是須要對非public方法添加註解,請考慮使用AspectJ(見下文)。
這裏有一個詳細的說明 http://stackoverflow.com/questions/4396284/does-spring-transactional-attribute-work-on-a-private-methodweb
相關博客:@Transactional 無效的解決方案spring