After 12 hours of trying I don't seem to be able to get Spring load time weaving working on Tomcat.
- Spring 4.2.1
- Hibernate 4.3.11
- Tomcat 8.09
I am trying to get an @Entity
autowired.
The weaver
output always says:
not weaving 'mypackage.MyEntity'
unless I also use a @Configuration
annotation on it. It will then weave but I get back A SPRIGNCGLIB
proxy where all the properties are null
.
If I remove the @Configuration
annotation (I don't think it should be there anyway) then I don't get any weaving and @Autowired
property is always null
.
This is my configuration:
applicationContext-beans.xml
<context:component-scan base-package="my.package" />
<context:spring-configured />
<context:load-time-weaver />
classes/META-INF/aop.xml
<aspectj>
<weaver options="-Xreweavable">
<include within="my.package.*"/>
</weaver>
<aspects>
<aspect name="org.springframework.beans.factory.aspectj.AbstractInterfaceDrivenDependencyInjectionAspect"/>
</aspects>
MyEntity.java
package my.package;
@Entity
@Table(name = "user")
@Configurable
public class User {
private Encrypter encrypter; // THE CLASS I WANT INJECTED
@Autowired
public void setEncrypter(Encrypter encrypter) {
this.encrypter = encrypter;
}
}
context.xml
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
The Tomcat lib
folder has (I am not sure it needs both of these):
- spring-instrument-4.2.1.RELEASE.jar
- spring-tomcat-weaver-2.5.6.SEC03.jar
The apps WEB-INF/lib
folder has:
- aspectjweaver-1.8.6.jar
- spring-aop-4.2.1.RELEASE.jar
- spring-aspects-4.2.1.RELEASE.jar
I have tried starting Tomcat with
-javaagent:D:/my/path/to/server/apache-tomcat-8.0.9/lib/spring-instrument-4.2.1.RELEASE.jar
but it didn't help and according to the Spring LTW documentation the context.xml
fragment is the preferred way to do this.
Does anyone have any ideas?