Spring Boot ConfigurationProperties未加载

时间:2018-10-02 18:05:40

标签: java spring-boot configuration

问题出在标题上。我看不到问题,因此我需要其他人关注。在这一点上,我开始认为IntelliJ正在困扰我。

@SpringBootApplication
@EnableEncryptableProperties
public class App
{
private static Logger logger = LoggerFactory.getLogger(App.class);


public static void main( String[] args )
{

    ApplicationContext cxt = SpringApplication.run(App.class, args);

   RIMService rim = cxt.getBean(RIMService.class);

所有属性类都是POJO

@Component
@ConfigurationProperties(prefix = "regulus")
public class RegulusProperties {

    private String soapUsername;
    private String soapPassword;
    private String repositoryName;
    private String wsdlLocation;
    private String dbServerName;
    private String databaseName;
    private String storedProcedureName;
    private String dbUsername;
    private String soapConnection;
<Getters and Setters>

regulusProperties通过Autowire在下面加载

@Component
public class RIMService {
final static Logger logger = LoggerFactory.getLogger(RIMService.class);



private RegulusProperties regulusProperties;

@Autowired
public void setRegulusProperties(RegulusProperties regulusProperties){
    this.regulusProperties = regulusProperties;
}

属性返回为空。

regulus.wsdlLocation=https://ix1rglscrpt3.am.rim.com/edms/edms_ws.asmx?WSDL
regulus.soapUsername= rim_regulus_c16
regulus.soapPassword=ENC(q1xHgKzfjFkiTLY0yVPiM2KD/sGairPC)

1 个答案:

答案 0 :(得分:0)

事实证明是IntelliJ和Maven搞砸了我。使用Maven Clean and compile,我将运行该应用程序,而不会加载任何@ConfigProperties。只需使用一个干净的方法,并允许IntelliJ编译和构建(通过运行该应用程序),它将起作用。当然很高兴我花了所有的时间来寻找不存在的配置错误。