无法将@ConfigurationProperties bean映射到@Component bean

问题描述 投票:0回答:1

配置类的实例是正确创建的,但未正确映射到@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不起作用,wmiProsnull

java spring
1个回答
0
投票

试试这个 :

@Component
@EnableConfigurationProperties(Wmi2017Properties.class)
public class WmiCollection {

    //@Autowired
    private Wmi2017Properties wmiProps;

public WmiCollection (Wmi2017Properties wmiProps){

this.wmiProps = wmiProps;
}
© www.soinside.com 2019 - 2024. All rights reserved.