春季AOP中的代理
使用事务性时,您要处理类的代理,因此在这种情况下:
@Transactionalpublic void doSomeThing(){ // calling this method targets a proxy doSomeThingElse(); // this method targets the actual class, not the PROXY, // so the transactional annotation has no effect}@Transactionalpublic void doSomeThingElse(){}您从外部调用代理,但是第二个方法调用是从代理对象内部进行的,因此没有事务支持。所以自然地,它们运行在同一事务中,无论第二种方法中@Transactional批注的值是多少
因此,如果您需要单独的交易,则必须致电
yourservice.doSomething();yourservice.doSomethingElse();
从外面。
整个场景在 **[Spring AOP
了解AOP代理](http://static.springsource.org/spring/docs/3.0.x/spring-framework-
reference/html/aop.html#aop-understanding-aop-
proxies)**(包括此“解决方案”)一章中得到了很好的解释:
从内部访问当前AOP代理对象
public class SimplePojo implements Pojo { public void foo() { // this works, but... gah! ((Pojo) AopContext.currentProxy()).bar(); } public void bar() { // some logic... }}


