Announcement Announcement Module
Collapse
No announcement yet.
How to troubleshoot Tomcat Loadtime Weaving? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to troubleshoot Tomcat Loadtime Weaving?

    Hi,

    I am having a very hard time getting Tomcat 7.0.23 and AspectJ LTW working with Spring 3.1. I have been able to get this setup working with previous versions, so I am not sure if I am running into a bug. Anyway here is what I have tried.

    1) Aspect is coded correctly because it gets woven in if I turn my web app project into an aspectJ project.
    2) For test purposes I created a command line app to run code that should have the aspect woven, and it worked, with the command line app I am using the same exact spring config file as I would in the container. LTW worked in this scenario since I passed the correct java agent to the start-up options, this leads to me to think that my spring.xml settings are correct.

    When running in tomcat the LTW does not work. Here is what I have done to configure tomcat.

    1) org.springframework.instrument.tomcat-3.1.0.RELEASE.jar is on my tomcat\lib folder
    2) <Loader loaderClass="org.springframework.instrument.classl oading.tomcat.TomcatInstrumentableClassLoader"/> is in my context.xml file for tomcat
    3) my aop.xml file contains


    Code:
    	<weaver options="-verbose -showWeaveInfo -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
    		<!-- only weave classes in our application-specific packages -->
    		<include within="com.example.status.tests.aspectj.*" />
    	</weaver>
    
    	<aspects>
    		<aspect name="com.example.status.tests.aspectj.ExampleAspect"/>
    		
    	</aspects>
    4) The tomcat console includes the following output that is related to AOP
    Code:
    06:24:56,891 INFO  [DefaultContextLoadTimeWeaver] Using a reflective load-time weaver for class loader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
    06:24:56,916 INFO  [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@7866eb46: defining beans [org.springframework.context.weaving.AspectJWeavingEnabler#0,org.springframework.context.config.internalBeanConfigurerAspect,loadTimeWeaver,org.springframework.context.weaving.AspectJWeavingEnabler#1,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,dojoToolkitConfiguration,homePageController,statusController,viewResolver,org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,statusTestSuite,dijitThemeName,dataSource,dojoBaseUrl,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
    06:24:57,028 INFO  [AspectJ Weaver] [AspectJ] AspectJ Weaver Version 1.6.12 built on Tuesday Oct 18, 2011 at 17:52:06 GMT
    06:24:57,028 INFO  [AspectJ Weaver] [AspectJ] register classloader org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader@30d1e7c2
    06:24:57,028 INFO  [AspectJ Weaver] [AspectJ] using configuration /Users/adib/pm-dev/workspaces/seedling/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SeedlingWeb/WEB-INF/classes/META-INF/aop.xml
    06:24:57,028 INFO  [AspectJ Weaver] [AspectJ] using configuration file:/Users/adib/pm-dev/workspaces/seedling/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/SeedlingWeb/WEB-INF/lib/org.springframework.aspects-3.1.0.RELEASE.jar!/META-INF/aop.xml
    06:24:57,031 INFO  [AspectJ Weaver] [AspectJ] register aspect com.example.status.tests.aspectj.ExampleAspect
    06:24:57,167 INFO  [AspectJ Weaver] [AspectJ] register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect
    06:24:57,196 INFO  [AspectJ Weaver] [AspectJ] register aspect org.springframework.scheduling.aspectj.AnnotationAsyncExecutionAspect
    06:24:57,206 INFO  [AspectJ Weaver] [AspectJ] register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect
    06:24:57,215 INFO  [AspectJ Weaver] [AspectJ] register aspect org.springframework.cache.aspectj.AnnotationCacheAspect

    And my ExampleAspect does not get woven in, even though as you can see it is being registered by AspectJ. I am really out of ideas on how to troubleshoot this problem after more than 5 hours of messing around I still could not get it working. Anyone know what steps I can take next to troubleshoot this problem.

  • #2
    I finally fixed this problem, it turns out to be a bug in Tomcat 7 which is scanning the class path to support features of Servlet 3.0 but the way that Tomcat scans the classpath causes the classes to be loaded before the Spring executes and has a chance to configure LTW. Problem can be fixed by changing the web.xml to version 2.5 of servlets or by adding metadata-complete="true" to the web-app element to tell tomcat that there is no need to scan the classpath.

    Bug details are at
    https://jira.springsource.org/browse/SPR-7440
    https://issues.apache.org/bugzilla/s...g.cgi?id=52549
    https://issues.apache.org/bugzilla/s...g.cgi?id=52444

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    	id="WebApp_ID" version="3.0" metadata-complete="true">

    Comment

    Working...
    X