配置类的实例是正确创建的,但未正确映射到@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
。
试试这个 :
@Component
@EnableConfigurationProperties(Wmi2017Properties.class)
public class WmiCollection {
//@Autowired
private Wmi2017Properties wmiProps;
public WmiCollection (Wmi2017Properties wmiProps){
this.wmiProps = wmiProps;
}