Announcement Announcement Module
Collapse
No announcement yet.
"Bridge" between AspectJ and Interceptors? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • "Bridge" between AspectJ and Interceptors?

    hi!

    Are there any utils/bridge stuff to define the pointcuts in the <aop> section with aspectj, and use the actual advice from an org.aopalliance.intercept.Interceptor ?

    This way I could define pointcuts in aspectj (which I prefer) - and reuse existing aop alliance based Interceptors.

  • #2
    Answering myself here:

    Yes - this is supported out of the box. Just define the pointcuts and point to the interceptor based beans.

    (I didn't realise that the interceptor's weren't called because the log-level wasn't activated)

    Comment


    • #3
      Originally posted by davidkarlsen View Post
      Yes - this is supported out of the box. Just define the pointcuts and point to the interceptor based beans.
      Can you explain that a bit? Suppose you have an interceptor that extends MethodInterceptor and use it as an advice for around aspect. You want to use aspectj-based pointcut now. But aspectj-based AOP assumes that you have an advice with the different signature - ProceedingJointPoint instead of the MethodInvocation, distinct parameters instead of the single parameters array. How does it works to fill old syntax-based interceptor with the joint point data?

      Comment


      • #4
        As stated it works. Because you still use spring you don't use AspectJ! We use the pointcut language to define where and when to apply the advice. The advice in this case can be an AspectJ aspect, a AOPAlliance one or a plain class (specifing which method to invoke).

        So it works out of the box...

        Code:
        <bean id="methodInvoker" class="SomeMethodInvokerInterceptor"/>
        <bean id="methodAspect" class="SomeMethodAspect" />
        <bean id="methodClass" class="SomeMethodPOJOClass" />
        
        <aop:config>
          <aop:pointcut id="serviceMethod" expression="execution(* *..*Service.*(..))"/>
          <aop:advisor pointcut-ref="serviceMethod" advice-ref="methodInvoker" />
        </aop:config>
        
        <aop:config>
          <aop:pointcut id="serviceMethod" expression="execution(* *..*Service.*(..))"/>
          <aop:advisor pointcut-ref="serviceMethod" advice-ref="methodAspect" />
        </aop:config>
        
        <aop:config>
          <aop:pointcut id="serviceMethod" expression="execution(* *..*Service.*(..))"/>
          <aop:aspect ref="methodClass">
            <aop:around pointcut-ref="serviceMethod" method="doOnMethodInvocation" />
          </aop:aspect>
        </aop:config>
        It is still Spring AOP although the way of expressing the when/where is AspectJ in the end it is still goint to be spring aop. So all three would work, although if you use the second you are probably better of with just using @Aspects or the initial aspectJ style aspects.

        Now if you where going to switch to loadtime weaving it would be a complete different story. But with the Proxy based approach it doesn't really matter what it is.

        Comment


        • #5
          Brilliant, thanks for direction!

          I checked AOP code related to that (namely DefaultBeanFactoryPointcutAdvisor and classes from org.springframework.aop.aspectj package)

          Comment

          Working...
          X