【发布时间】:2015-03-20 13:20:39
【问题描述】:
我有一组在 Spring 之外实例化的非托管类。我一直在尝试使用带有加载时间的 Spring AOP 将 @Autowire 一个 bean 编织到这些类中,但到目前为止还没有任何运气。
我一直在使用 Tomcat 8 和 Spring Boot 1.2.0 进行测试。
我尝试设置课程的@Configuration 如下所示:
@Configuration
@PropertySource("classpath:application.properties")
@EnableSpringConfigured
@EnableLoadTimeWeaving
public class Config
在Config 内部,我将我想要@Auotwire 的bean 定义到我的非托管类中:
@Bean
public StateProvider stateProvider() {
//setup bean
return new DynamoStateProviderImpl( );
}
非托管 bean 如下所示:
@Configurable(autowire = Autowire.BY_TYPE, dependencyCheck = true, preConstruction = true)
public class StateOutput implements UnifiedOutput {
@Autowired
private StateProvider stateProvider;
我的 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>
到目前为止,我还没有看到任何注入 stateProvider 的内容,也无法从日志中提取任何信息。我也尝试过使用
@Autowired
public void setStateProvider(StateProvider stateProvider){
this.stateProvider = stateProvider;
}
谢谢
【问题讨论】:
标签: java spring spring-boot aspectj spring-aop