0

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?

Doahh
  • 590
  • 1
  • 8
  • 20
  • 1
    Why on earth d you have a 2.5.6 jar in your path? You are mixing different versions of a framework don't ever do that... Also remove the `aop.xml` as Spring already provides one that includes the needed aspects, you are also referencing the wrong one here (the base class not the actual aspect). Last thing to say load-time weaving and `@Configurable` are different beasts (although one extends the other). You want to inject dependencies into non managed beans, you should be able to do that without ``. – M. Deinum Sep 28 '15 at 09:12
  • 1
    You need [this section](http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#aop-atconfigurable) of the reference guide. – M. Deinum Sep 28 '15 at 09:15

0 Answers0