Announcement Announcement Module
Collapse
No announcement yet.
AOP interceptors issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP interceptors issue

    I don't think that it's possible to completely resolve my issue because it's not reproduced at simple test cases. Anyway, may be somebody can give a direction to the right way.

    So, I have a number of classes that I'd like to advice. They all located at the same package and joinpoint methods have the same names and visibility (public) . The only difference is type of input paramter. I use the same settings for advicing them but only half of advices apply. I noticed (logging and debugging) that all of target beans (even that beans that don't apply aspect) are proxied with cglib enhancer. And I noticed that there is a difference at object
    Code:
    this.interceptorsAndDynamicMethodMatchers object
    that is located at call stack
    Code:
    proceed():138, org.springframework.aop.framework.ReflectiveMethodInvocation
    intercept():630, org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor
    process():-1, my.BusinessObject$$EnhancerByCGLIB$$8011c0d8
    ...my.business.Object.method()    ...
    In the case when aspect is applied, this.interceptorsAndDynamicMethodMatchers contains two entries:
    Code:
    [0] = {[email protected]072}
    [1] = {org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor@4085}
    When aspect is not applied, only the following entry presents:
    Code:
    [0] = {[email protected]072}
    I suppose this to be a cause of problem but absolutely don't understand the reasons of such behaviour.

    Aspects are configured at the following way:
    Code:
        <bean id="testAspect1" class="com.MyAspect1">
        </bean>
    
        <bean id="testAspect2" class="com.MyAspect2">
        </bean>
    
        <aop:config proxy-target-class="true">
            <aop:aspect ref="testAspect1">
                <aop:before method="doProcessing"
                            pointcut="execution(public void com.BusinessObject1.process(..))"/>
            </aop:aspect>
            <aop:aspect ref="testAspect2">
                <aop:before method="doProcessing"
                            pointcut="execution(public void com.BusinessObject2.process(..))"/>
            </aop:aspect>
        </aop:config>
    Any thoughts?

  • #2
    One more detail - classes com.BusinessObject1 and com.BusinessObject1 are generified and corresponding joinpoint methods are generfiied by input argument type. In the case of unapplied advice I found out that incorrect method is examined by pointcut at
    Code:
    intercept():597,org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor
    Incorrectness is at argument type - Object instead of my type (defined via generics). For this method corresponding this.methodCache contains list contains only one element of class
    Code:
    org.springframework.aop.interceptor.ExposeInvocationInterceptor
    (for method with correct argument there is a list with two elements:
    Code:
    [0] = {[email protected]072}
    [1] = {org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor@4085}
    )
    This seems rather strange..

    Comment


    • #3
      How does it look a method from BusinessObject1 and BusinessObject2 which should be intercepted and actually is not ?
      And which Spring version are you using ?

      Comment


      • #4
        Spring 2.0.5.

        Classes look like below:
        Code:
        public interface DataProcessor<T> {
            void process(T message) throws RuntimeException;
        }
        
        public class DataProcessor1 implements BusinessDataProcessor<Entity1> {
            public void process(Entity1 entity) {
                ...
            }
            ...
        }
        
        public class DataProcessor2 implements BusinessDataProcessor<Entity2> {
            public void process(Entity2 entity) {
                ...
            }
            ...
        }
        (interface, classes and argument type names are changed)

        Both class are adviced and I see (via debugger) that after call to process() value of method argument at
        Code:
        intercept():597,org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor
        is like (working aspect)
        Code:
        com...DataProcessor1.process(com...Entity1)
        and (nonworking aspect)
        Code:
        com...DataProcessor2.process(java.lang.Object)

        Comment


        • #5
          There is a bug fixed for 2.0.7, which, I think, is related to your problem:
          http://opensource.atlassian.com/proj...rowse/SPR-3556

          Comment


          • #6
            This might seem an easy answer, but could you try switching spring to version 2.0.7?

            A number of generics related AOP issues have been fixed in that release.

            Comment


            • #7
              Yep, thanks to all.
              2.0.7 release really solves the problem.

              Comment

              Working...
              X