Spring Load @Autowire into an unmanaged class using @Configurable and load the weave time

I have a set of unmanaged classes that I created outside of Spring. I am trying to use Spring AOP with loading time in @Autowire a bean in these classes, but still no luck.

I tested with Tomcat 8 and Spring Boot 1.2.0.

My @Configuration , where I am trying to configure a class, is as follows:

 @Configuration @PropertySource("classpath:application.properties") @EnableSpringConfigured @EnableLoadTimeWeaving public class Config 

Inside Config I define a bean I want @Auotwire in my unmanaged classes:

 @Bean public StateProvider stateProvider() { //setup bean return new DynamoStateProviderImpl( ); } 

An unmanaged bean is as follows:

 @Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true, preConstruction = true) public class StateOutput implements UnifiedOutput { @Autowired private StateProvider stateProvider; 

And I have the following fingerprints inside my pom

  <dependency> <groupId>org.springframework</groupId> <artifactId>spring-agent</artifactId> <version>2.5.6.SEC03</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <dependency> <groupId>javax.el</groupId> <artifactId>javax.el-api</artifactId> <version>3.0.0</version> </dependency> 

Until now, I could not see anything entered in stateProvider or was able to pull any information from the logs. I also tried to introduce a setter style using

 @Autowired public void setStateProvider(StateProvider stateProvider){ this.stateProvider = stateProvider; } 

thanks

+7
java spring spring-aop spring-boot aspectj
source share
1 answer

For the LTW tool, you need to either use javaagent or place spring-tomcat-weaver.jar in the \lib folder and configure TomcatInstrumentableClassLoader in context.xml .

Javaagent example:

 -javaagent:"${settings.localRepository}/org/springframework/spring-agent/2.5.6.SEC03/spring-agent-2.5.6.SEC03".jar 

ClassLoader example:

 <Context> <Loader loaderClass="org.springframework.instrument.classl oading.tomcat.TomcatInstrumentableClassLoader" /> </Context> 
+3
source share

All Articles