public interface AService {
public void a();
public void b();
}
@Service()
public class AServiceImpl implements AService{
@Transactional(propagation = Propagation.REQUIRED)
public void a() {
this.b();
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void b() {
}
}
因为Service实现了个接口,使用代理时走的是动态代理,因此 a() 方法执行的时候使用的时Service类的代理对象,
而this.b()使用的是未代理类AServiceImpl 的b方法,b方法是没有使用AOP的。
先说解决方法:
this.b();-----------修改为--------->((AService) AopContext.currentProxy()).b();