Spring - How 'multiple' AOP behaviors to services are resolved?
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 methodsomeOtherMethod()
.
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.
精彩评论