Announcement Announcement Module
Collapse
No announcement yet.
Issues with Spring AOP and Google App Engine Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issues with Spring AOP and Google App Engine

    Hi everyone,

    I'm new to Spring AOP and was trying to practice a bit by creating a small web project for the Google App Engine. Unfortunately, I can't get my example to run. I was going to set up a tracer-aspect that should produce log output for Operations that are annotated with the @Traced annotation i created for this purpose. Here is my aspect:

    Code:
    @Aspect
    public class TraceAspect {
    
            // This pointcut should match any operation in the package chargen and its sub-packages, which are annotated with the chargen.aspect.Traced annotation
    	@Pointcut("execution(* chargen..*.*(..)) && @annotation(chargen.aspect.Traced)")
            public void tracedOperation() {}
    	
            // This advice should be run before the "tracedOperation()" pointcut
    	@Before("chargen.aspect.TraceAspect.tracedOperation()")
    	public void logBefore(Traced traced) {
    		System.out.println("intercepted before call ");
    	}
    	
            // This advice should be run after the "tracedOperation()" pointcut
    	@After("chargen.aspect.TraceAspect.tracedOperation()")
    	public void logAfter(Traced traced) {
    		System.out.println("intercepted after call ");
    	}
    }
    I have configured my beans.xml according to http://static.springsource.org/sprin...rence/aop.html (added <aop:aspectj-autoproxy/> plus namespaces and configured my aspect as a Spring bean.

    If I run my example, nothing happens. Neither Exceptions are thrown nor any advice is beeing executed. I figure I must have made some mistake, but I have been comparing my code and config to the tutorial over and over again, not beeing able to figure out what I have done wrong. I'm using a DefaultListableBeanFactory to create my Spring beans. Are there any known issues with Spring AOP and Google App Engine? Does anybody know what i'm doing wrong? Any help is highly appreciated.

  • #2
    For starters you have a pointcut without arguments (your tracedOperation has no parameter) so it doesn't match. Either add it to the method or move the @annotation part to the before/after methods.

    Comment


    • #3
      Thanks for pointing that out. Guess I have to read the tutorial again. I have now adjusted my aspect as follows:

      Code:
      @Aspect
      public class TraceAspect {
      
      	@Pointcut("execution(* chargen..*.*(..))")
              public void anyOperation() {}
      	
      	@Before("chargen.aspect.TraceAspect.anyOperation() && @annotation(chargen.aspect.Traced)")
      	public void logBefore(Traced traced) {
      		System.out.println("intercepted before call ");
      	}
      	
      	@After("chargen.aspect.TraceAspect.anyOperation() && @annotation(chargen.aspect.Traced)")
      	public void logAfter(Traced traced) {
      		System.out.println("intercepted after call ");
      	}
      }
      Unfortunately, my annotated methods still won't be advised. I have just realized, that the method I want to be advised has an @Override annotation in addition to the @Traced annotation. Could it be that the advice is not being matched due to the additional annotation? Are annotations matched inclusively or exclusively?

      Comment


      • #4
        The extra annotation shouldn't matter.

        Make sure the bean you want to advice is in the same context as the aspect and the aop:aspectj-autoproxy... Also make sure you are using the beans and not creating new instances yourself.

        Comment


        • #5
          Thank you for your help, Marten. I think, I found the problem. The Spring AOP feature seems to require an application context. I was just using a default listable bean factory. Now that I have refactored my code to use an app context, I get the following exception:

          Code:
           org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor:
          This means Spring is trying to setup the aspect and fails, due to restrictions of the Google App Engine, I fear. I'm pretty sure I've got all the required jar's (double checked this). I have sort of expected this. If anybody knows about any issues with Spring AOP and GAE and knows how to work arround them, I would highly appreciate any sort of help.

          Comment


          • #6
            Judging from the stack trace you are missing the aopalliance.jar... I suggest using maven/ant+ivy/gradle to manage your dependencies, that should save you a whole lot of headaches. If this wouldn't work nothing would work (transactions etc. are implemented with aop as well).

            Comment


            • #7
              yes... I know I should use maven. I have never tried maven, though and thought I could take one step at a time. But maybe it helps to get hurt before using smart build systems, so I know exactly from what kind of mistakes they protect me. Again, thank you for your help, Marten. I shall try the aopalliance.jar tomorrow.

              Comment

              Working...
              X