Announcement Announcement Module
Collapse
No announcement yet.
Tomcat Load time weaving with Java Config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tomcat Load time weaving with Java Config

    As the attached example shows, the load time weaving is working with Xml configuration and not with Java config.
    I have the spring-instrument-tomcat.jar in the tomcat lib.
    I've used Netbeans 7.3.1 with Tomcat 7.0.34.
    Same result for Spring 3.2.2 and 3.2.3.

  • #2
    For starters your web.xml is flawed, it has the wrong version (2.5 as opposed to 3.0).

    Next to that your config class that enables loadtime weavig also depends on the class Person. This could lead to the situation where the class already got loaded before the loadtimeweaver can kick in (already loaded classes cannot be processed).

    Comment


    • #3
      changed web.xml to
      "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5" and moved @EnableSpringConfigured, @EnableLoadTimeWeaving, @EnableAspectJAutoProxy to the WebAppInitializer does not help.

      I've also tried to put the Person bean in another config file, still doesn't work.

      Comment


      • #4
        Fixed web.xml.
        With Xml configuration it is working both 2.5 and 3.0

        Attachment
        Attached Files

        Comment


        • #5
          For a WebAppInitializer to work you need a servlet 3.0 container, you are setting it to be 2.5... That way it isn't going to work.

          Also the @Enable* annotations need to be on @Configuration classes not on WebAppInitializer classes.

          Comment


          • #6
            Removed web.xml completly, switched to servlet 3.0 - no help


            Attachment
            Attached Files

            Comment


            • #7
              And it won't work in yuor setup...

              Originally posted by Marten Deinum
              Next to that your config class that enables loadtime weavig also depends on the class Person. This could lead to the situation where the class already got loaded before the loadtimeweaver can kick in (already loaded classes cannot be processed).

              Comment


              • #8
                Thanks for the help so far...

                Tried to put it on other config class, that gets loaded before the one that the Person... still no help. Is there somewhere a working example with LTW and Java config?
                Last edited by zoltan.puskai; Jul 15th, 2013, 05:50 AM.

                Comment


                • #9
                  All the config classes are loaded at the same time so that will not make any difference. In general class is loaded as soon as it is referenced (i.e. import statement)... I suspect that if you put the Person class in an xml file, and import that with @ImportResource that it will work.

                  Comment


                  • #10
                    I try to avoid xml configuration. LTW with xml config is working fine.

                    Comment


                    • #11
                      Does it make sense to have the @EnableLoadTimeWeaving on a configclass, if the beans are loaded before the aspect is processed?

                      Found similar issue on http://forum.springsource.org/showth...r-gt-is-worked!

                      Comment


                      • #12
                        The beans aren't loaded the classes are (there is a difference)...

                        As long as you prevent your Person class from being loaded before the EnableLoadTimeWeaving is in place you are good to go, but as you have defined your bean explicitly this eagerly loads the class and as such makes it not eligble anymore for loadtime weaving (as it is already loaded). (Hence my suggestion to move this part to xml instead of java).

                        It works fine with component-scanning as classes are loaded after the registration of the loadtime weaver.

                        This is one of the drawbacks, imho, of the java approach as classes might get eagerly loaded before loadtime weaving can be applied.

                        Comment


                        • #13
                          Moved it to xml, used @ImportResource, still not working.

                          Comment


                          • #14
                            Make sure you don't reference the class in your configuration anymore (or other classes which get loaded due to imports/references in your context).

                            Comment


                            • #15
                              I've made everything as suggested.

                              I have also turned on aop debugging.

                              from the logs it seems, that DefaultContextLoadTimeWeaver setBeanClassLoader is called twice

                              Code:
                              INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@345539be: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,config,beanConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.context.annotation.aspectj.SpringConfiguredConfiguration,org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.LoadTimeWeavingConfiguration,loadTimeWeaver,hu.arthus.test.domain.Person#0]; root of factory hierarchy
                              júl. 15, 2013 4:48:05 DU org.springframework.context.weaving.DefaultContextLoadTimeWeaver setBeanClassLoader
                              INFO: Using a reflective load-time weaver for class loader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
                              júl. 15, 2013 4:48:05 DU org.springframework.context.weaving.DefaultContextLoadTimeWeaver setBeanClassLoader
                              INFO: Using a reflective load-time weaver for class loader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
                              also the class is woven

                              Code:
                              [TomcatInstrumentableClassLoader@58ac78ec] weaveinfo Extending interface set for type 'hu.arthus.test.domain.Person' (Person.java) to include 'org.springframework.beans.factory.aspectj.ConfigurableObject' (AnnotationBeanConfigurerAspect.aj)
                              [TomcatInstrumentableClassLoader@58ac78ec] weaveinfo Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'hu.arthus.test.domain.Person' (Person.java:8) advised by before advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (AbstractDependencyInjectionAspect.aj:80) [with runtime test]
                              [TomcatInstrumentableClassLoader@58ac78ec] weaveinfo Join point 'initialization(void org.springframework.beans.factory.aspectj.ConfigurableObject.<init>())' in Type 'hu.arthus.test.domain.Person' (Person.java:8) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (AbstractDependencyInjectionAspect.aj:89) [with runtime test]
                              [TomcatInstrumentableClassLoader@58ac78ec] weaveinfo Join point 'initialization(void hu.arthus.test.domain.Person.<init>())' in Type 'hu.arthus.test.domain.Person' (Person.java:8) advised by afterReturning advice from 'org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect' (AbstractDependencyInjectionAspect.aj:89) [with runtime test]
                              In the xml version DefaultContextLoadTimeWeaver setBeanClassLoader is called only once.

                              Can this be the source of the problem?

                              (I've tried to turn on/off @EnableSpringConfigured with no help)

                              Attachment
                              Attached Files

                              Comment

                              Working...
                              X