Announcement Announcement Module
Collapse
No announcement yet.
Load-time weaving in Tomcat6 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load-time weaving in Tomcat6

    Hi,

    I met the following problem - if I put
    Code:
        <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
    into the "default" Tomcat context.xml (inside the conf directory) the instrumented classoader is recognized and load time weaving works. If I instead put the same string in the context.xml inside application's META-INF directory I obtain

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExc eptionTranslationPostProcessor#0' defined in class path resource [app-ctx-fbs-integration-jpa-techarch.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'entityManagerFactory' defined in class path resource [app-ctx-fbs-integration-jpa-techarch.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'loadTimeWeaver': Initialization of bean failed; nested exception is java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
    org.springframework.instrument.tomcat-3.0.4.RELEASE.jar is in the Tomcat's lib directory.

    What may be the problem?

  • #2
    Exception shows that your application was loaded by Tomcat's own WebappClassLoader, rather than Spring's TomcatInstrumentableClassLoader - so your Tomcat configuration might have failed. Maybe you should try putting loaderClass attribute under the <Loader> element like this:

    Code:
    <Context path="/my-application">
        <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
    </Context>
    as explained here.

    Also, if you are using Tomcat 5.5 (versions 5.5.20 or later), try setting useSystemClassLoaderAsParent="false" on the <Loader> element to prevent a known issue.

    Comment


    • #3
      What the exception shows I know - I am wondering why it shows what it shows.
      Tomcat version is 6.0.29 - sorry, forgot to mention it in the original post.
      And it fails with the message said exactly in the case when I put loader element exactly as you (and Spring reference) said

      Originally posted by Osvaldas Grigas View Post
      Exception shows that your application was loaded by Tomcat's own WebappClassLoader, rather than Spring's TomcatInstrumentableClassLoader - so your Tomcat configuration might have failed. Maybe you should try putting loaderClass attribute under the <Loader> element like this:

      Code:
      <Context path="/my-application">
          <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
      </Context>
      as explained here.

      Also, if you are using Tomcat 5.5 (versions 5.5.20 or later), try setting useSystemClassLoaderAsParent="false" on the <Loader> element to prevent a known issue.

      Comment


      • #4
        Make sure that after you deploy WAR to Tomcat, there is actually a context.xml file under %TOMCAT_ROOT%/webapp/your-app-name/META-INF directory. Also, make sure that Tomcat automatically copied this file to conf directory: it should be named %TOMCAT_ROOT%/conf/Catalina/localhost/your-app-name.xml

        Tomcat looks for META-INF/context.xml NOT in the classpath, but in the exploded WAR directory. So make sure that you put it in the right place in your project before packaging.

        Comment


        • #5
          Application is deployed unpacked (not as war) and context.xml file is in the right place (Loader is not the only element there ).

          But you are right - for some reasons contxt xml is not copied to %TOMCAT_ROOT%/conf/Catalina/localhost/my-app-name.xml
          Now have to investigate, why.

          Comment


          • #6
            Tomcat documentation does state explicitly (at http://tomcat.apache.org/tomcat-6.0-...g/context.html)
            Only if a context file does not exist for the application in the $CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xml inside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase.
            So it does not state clearly that copying occurs if the application is deployed unpacked (but id does so - unless a context file for application already exists in $CATALINA_BASE/conf/[enginename]/[hostname]/).


            Anyhow the situation is clear now, thank you Osvaldas

            Comment

            Working...
            X