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

  • Spring AOP with Tomcat

    Can someone tell me what I need to do in order to get Spring AOP working with Tomcat? I get the exception below:
    Unexpected exception parsing XML document from class path resource [Aspects.xml]; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

    I have the aspect-weaver.jar, spring-agent.jar, and aspectjrt.jar in my development environment. Do these also need to be inlcuded in my web project?

  • #2
    Assuming you're using @AspectJ aspects, you need to have aspectjrt.jar and aspectjweaver.jar in your application classpath. See here:

    http://static.springframework.org/sp...spectj-support

    Comment


    • #3
      Spring AOP with Tomcat

      I was actually looking more at using the "Schema based AOP support". Now, I don't understand clearly but in using this approach do I still need to declare my Apsect class like the following:

      @Aspect
      class myClass{}

      Comment


      • #4
        No... But you still need the aspectj jars on your classpath.

        Comment


        • #5
          Spring AOP with Tomcat

          Alright I have that working with Tomcat now. But, I get this error and have searched online (probably in the wrong location) and found nothing.

          Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigExcepti on: Could not generate CGLIB subclass of class com.foo.Test Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given

          The class is not final, i don't have a non-visable class. I am using the cglib jar. Any other ideas?

          Comment


          • #6
            If you're proxying a concrete class with CGLib (instead of an interface with a dynamic proxy), the class needs to have a default (i.e., no-arg) constructor.

            Comment


            • #7
              As stated by Mike and hinted on by your stacktrace

              Code:
              nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
              When using CGLib classproxies a non-argument constructor is required.

              Comment


              • #8
                Spring AOP with Tomcat

                Alright..... But I shouldn't have to do that if I have interfaces. According to the documentation. Can someone point me to documentation on why this has to work this way? It just doesn't seem to make sense? In every class I need to put an empty constructor just to use Spring AOP?

                Comment


                • #9
                  You only need the no-arg constructor if you're proxying a concrete class with CGLib instead of an interface with a dynamic proxy. Does your com.foo.Test class implement any interface(s)?

                  Comment


                  • #10
                    Spring AOP with Tomcat

                    Yes, I am implementing an interface. So if I have a class I want to inspect that extends an abstract class and that abstract class implements an interface, do I still need an empty constructor? That is what it is telling me I need. Just verifying this is correct.

                    Comment


                    • #11
                      The fact that you implement an interface doesn't automatically mean that you don't use CGLib. If you have proxyTargetClass set to true (or similair properties) you use cglib. Apparently that is the case somewhere.

                      That is what it is telling me I need.
                      So you need it or disable class proxying...

                      Comment


                      • #12
                        Spring AOP with Tomcat

                        Ok. I used the empty constructor and everything is working fine. Thanks everyone for answering my questions. I guess I was just looking for a work around trying to avoid empty constructors everywhere.

                        Comment


                        • #13
                          Normally, it is preferable to use dynamic proxies over CGLIB proxies.

                          Really, this is Spring default behavior as far as proxied class implements at least one interface and Spring is not instructed specifically to use CGLIB-proxies (by proxy-target-class="true").. Really, it is described in Spring reference quite well (Chapter 6.6 in Spring 2.5.1 Reference).

                          As soon as dynamic proxying is used you have no need in the default constructor.

                          Regards,
                          Oleksandr

                          Originally posted by Huskie009 View Post
                          Ok. I used the empty constructor and everything is working fine. Thanks everyone for answering my questions. I guess I was just looking for a work around trying to avoid empty constructors everywhere.

                          Comment

                          Working...
                          X