【发布时间】:2016-08-31 01:18:01
【问题描述】:
新手春季问题。我有一个正确注释的 @Component 类,它为我带来了我的环境配置。
@Component
public class EnvConfig {
//...
}
因为它是一个@Component,它会被自动注入提取出来。
但是这个类的调用者是一个普通的数据bean。普通数据 bean 有一个特殊的实用方法需要访问这个类。
public class EmployeeBean {
@Autowired
EnvConfig envConfig;
//...
public void getSpecialInfo()
{
envConfig.method1();
envConfig.method2();
}
}
当我调试这个方法时,envConfig 是 NULL。
所以 Autowired 对象的调用者也需要是@Component、@Service 或@Repository?
【问题讨论】:
标签: spring