配置类的实例已正确创建,但未正确映射到@Component
类,显示为null
。为什么要@Component
类注释,因为@Autowired
似乎根本不起作用?谢谢。
@Configuration
@ConfigurationProperties(prefix="wmi2017")
@PropertySource(value = "classpath:wmi2017.properties", ignoreResourceNotFound = false)
public class Wmi2017Properties {
}
- >没有@Configuration
,这不起作用
@Component
@EnableConfigurationProperties(Wmi2017Properties.class)
public class WmiCollection {
@Autowired
private Wmi2017Properties wmiProps;
@Autowired
不起作用且wmiPros
为null
。
答案 0 :(得分:0)
试试这个:
@Component
@EnableConfigurationProperties(Wmi2017Properties.class)
public class WmiCollection {
//@Autowired
private Wmi2017Properties wmiProps;
public WmiCollection (Wmi2017Properties wmiProps){
this.wmiProps = wmiProps;
}