Announcement Announcement Module
Collapse
No announcement yet.
AOP works with integration test, but not in Tomat. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP works with integration test, but not in Tomat.

    I am using annotations to perform the aop. Everything works great in my integration test when I extend the AbstractJUnit4SpringContextTests class. However, when I deploy the application to Tomcat the aop does not work. What is really confusing is that I do not get any errors either (in my app or the tomcat logs), it just fails to call the aspect.

    I have been looking at this for a few days and I haven't had any luck. Whats interesting is that I can do something like put in an invalid Pointcut annotation and I will get stack trace errors when I start up, so I know that my aspect is being read at startup.

    Any ideas on what I am missing?

    I have all the required jar files in my app.
    asm-2.2.3.jar
    asm-commons-2.2.3.jar
    asm-util-2.2.3.jar
    aspectjrt.jar
    aspectjweaver.jar


    I also put the following in the tomat lib directory (although I don't think I need to):
    spring-agent.jar
    spring-aspects.jar
    spring-tomcat-weaver.jar

    I also tried deploying to Glassfish with similar results. I would be happy to post any other code, but my real question is why does it work with an integration test but fail in Tomcat.

    Is there any way I can log out what Spring thinks it should be performing aop on at startup. Part of the complexity of aop is it just magically happens behind the scenes so its hard to troubleshoot.

    I am using Spring 2.5.3, Tomcat 6, and JDK6

    -Jeff Johnston

  • #2
    After days of looking I finally figured it out..... I had to put the aop annotation config settings in my spring-servlet.xml file.

    <context:annotation-config/>
    <context:component-scan base-package="com.roomandboard" />
    <aop:aspectj-autoproxy/>

    I figured it out by setting my logging to debug and sifted through the logs. The logs were telling me that the annotation settings were being overwritten to not perform the proxy settings.

    Does this seems like a bug? I am going to write up a bug report just in case. For sure not overly intuitive!

    -Jeff Johnston

    Comment


    • #3
      You need to register the aop stuff for each ApplicationContext you use.

      I guess you use both a ContextLoaderListener and a DispatcherServlet and configured the context:annotation-config in the context loaded by the ContextLoaderListener. Those settings do nothing for child contexts (the context of your DispatcherServlet).

      Comment


      • #4
        That makes sense to me, except the bean I have the aspect for is in the bean factory loaded by the ContextLoaderListener. I wouldn't think that the bean factory loaded by the DispatcherServlet would effect the other one.

        I think it is a bug that the one factory basically overrides the settings for the aop stuff in the other. Or maybe its just that it silently overrides the settings which makes it very difficult to debug.

        Comment


        • #5
          It doesn't and even cannot override the aop configuration...

          Next to that make sure that you have everything setup correctly. You use component scanning, so that also might screw things up. If you detect the same beans you end up with 2 instances (1 in the CLL context and 1 in the DS context). And if you then have setup aop in the CLL context that bean will have aop applied, if you haven't set it up in your DS context that bean doesn't have aop applied.
          Last edited by Marten Deinum; Apr 11th, 2008, 10:39 AM.

          Comment


          • #6
            Ok, so you are saying that I need to be more careful about which beans I scan in the different bean factories. That makes sense. I will be more explicit about what gets scanned then. Not saying I have a solution, but it is still a pretty mysterious situation to get into though. Things just quit working silently, which is very much not like Spring .

            Thank you for your replies .

            Comment

            Working...
            X