I'm having trouble loading in time to work with Spring in my Tomcat 6 webapp. I want to use it only for transactions (so self-communication takes into account transactional annotations that are not related to AOP proxying). It seems like the weaver is loading, but my annotated classes are not actually woven. When I look through my code, I do not see transaction boundaries in SQL logs, as I observed with the usual AOP proxy configuration. Here is my setup:
In server.xml:
<Context path="/api" allowLinking="true" reloadable="false" docBase="/usr/local/apache-tomcat-6.0.18/webapps/API/ROOT" workDir="/usr/local/apache-tomcat-6.0.18/webapps/API/ROOT/work"> <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/> </Context>
I have a spring -tomcat-weaver.jar tomcat / lib directory and the following jars on the Tomcat path:
cat / WebApps / API / ROOT / WEB-INF / Library / aspectjweaver.jar cat / WebApps / API / ROOT / WEB -INF / Library / spring -aspects.jar
This is in the bean configuration file where annotated service classes are defined:
<tx:annotation-driven transaction-manager="txManager" mode="aspectj"/>
In one of many other bean configuration files in my context:
<aop:aspectj-autoproxy> <aop:include name="methodTimer"/> </aop:aspectj-autoproxy> <context:load-time-weaver aspectj-weaving="on"/> <context:annotation-config /> <bean name="methodTimer" class="tv.current.web.aop.MethodTimer" />
I want MethodTimer to use a regular AOP proxy, not LTW-LTW, should only apply to @Transactional annotations. As described here: http://static.springsource.org/spring/docs/2.5.x/reference/aop.html#aop-aj-configure . If I comment on the <aop:aspectj-autoproxy> , I do not receive any of the weave log messages that I see otherwise. Speaking of this, here they are; you can see that the aspects are loading, but nothing is actually woven:
Aug 28, 2009 6:34:42 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring root WebApplicationContext [TomcatInstrumentableClassLoader@34fe7e0e] info AspectJ Weaver Version 1.6.5 built on Thursday Jun 18, 2009 at 03:42:32 GMT [TomcatInstrumentableClassLoader@34fe7e0e] info register classloader org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader@34fe7e0e [TomcatInstrumentableClassLoader@34fe7e0e] info using configuration file:/usr/local/apache-tomcat-6.0.18/webapps/API/ROOT/WEB-INF/lib/spring-aspects.jar!/META-INF/aop.xml [TomcatInstrumentableClassLoader@34fe7e0e] warning ignoring duplicate definition: jar:file:/usr/local/apache-tomcat-6.0.18/webapps/API/ROOT/WEB-INF/lib/spring-aspects.jar!/META-INF/aop.xml [TomcatInstrumentableClassLoader@34fe7e0e] info register aspect org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect [TomcatInstrumentableClassLoader@34fe7e0e] info register aspect org.springframework.transaction.aspectj.AnnotationTransactionAspect [TomcatInstrumentableClassLoader@34fe7e0e] info processing reweavable type org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect$ConfigurableDeserializationSupport: org/springframework/beans/factory/aspectj/AbstractInterfaceDrivenDependencyInjectionAspect.aj [TomcatInstrumentableClassLoader@34fe7e0e] info successfully verified type org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect exists. Originates from org/springframework/beans/factory/aspectj/D:\projects\spring\spring\aspectj\src\org\springframework\beans\factory\aspectj\AnnotationBeanConfigurerAspect.aj [TomcatInstrumentableClassLoader@34fe7e0e] info successfully verified type org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect exists. Originates from org/springframework/beans/factory/aspectj/D:\projects\spring\spring\aspectj\src\org\springframework\beans\factory\aspectj\AbstractInterfaceDrivenDependencyInjectionAspect.aj [TomcatInstrumentableClassLoader@34fe7e0e] weaveinfo Type 'org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect$ConfigurableDeserializationSupport' (AbstractInterfaceDrivenDependencyInjectionAspect.aj) has intertyped method from 'org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect' (D:\projects\spring\spring\aspectj\src\org\springframework\beans\factory\aspectj\AbstractInterfaceDrivenDependencyInjectionAspect.aj:'java.lang.Object org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect$ConfigurableDeserializationSupport.readResolve()')
As you can see from the logs, I do not have my own aop.xml file, I use the default value in spring -aspects.jar, which looks like this:
<aspectj> <!-- <weaver options="-showWeaveInfo"/> --> <aspects> <aspect name="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"/> <aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/> </aspects> </aspectj>
I do not need to start Tomcat with -javaagent:/path/to/spring-agent.jar , right? Because I specified the correct ClassLoader in server.xml and see how the loader becomes familiar. Am I mistaken about this? Do I need spring -agent.jar anywhere, either in tomcat / lib, or in my tomcat path? Do I need aspectjweaver.jar in tomcat / lib? What else am I missing? Any help would be greatly appreciated as I struggled with this for almost two days.
Edit: Another (perhaps very important) detail that I missed is that I am developing in Eclipse and using the Sysdeo Tomcat Plugin to run Tomcat. Try running Tomcat from the command line and see if this has changed ...