开发者

Spring - How 'multiple' AOP behaviors to services are resolved?

开发者 https://www.devze.com 2022-12-09 18:56 出处:网络
I want to know that whether we can apply \'multiple\' AOP behaviors to our service classes or not? Lets just say, i do this to my BankServiceImpl class:

I want to know that whether we can apply 'multiple' AOP behaviors to our service classes or not?

Lets just say, i do this to my BankServiceImpl class:

  • @Transactional on top of one of the method, accountTransfer(), and
  • and some custom <aop> pointcut on th开发者_JAVA百科e execution of another method someOtherMethod().

Then will Spring be able to generate one proxy where accountTransfer() is made transactional and someOtherMethod() is also given aop behaviour?

Does any one has an idea on how Spring resolves multiple AOP behaviors?


It looks like Spring creates a single proxy object with all of the advice types in it. This proxy object will implement the org.springframework.aop.framework.Advised regardless of if it's a JDK dynamic proxy or a CGLIB proxy.

If you have multiple advisors, the order of their execution is undefined unless you make it explict by implementing the Ordered interface or the @Ordered annotation. You can find more on ordering here. Springs transactional aspects default to lowest priority.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号