ConfigurationProperties does not bind properties

后端 未结 2 888
醉梦人生
醉梦人生 2021-02-19 02:22

I want to bind my application.properties into a class automatically by using @ConfigurationProperties annotation. First, I tried with @Value annotation and was able to inject pr

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 03:11

    The main problem is that you do not have setters. When you put setters to ConfigBuilder works fine. The ConfigBuilder must be like this

    @Component
    @ConfigurationProperties(prefix="my")
    public class ConfigBinder {
    
        private String name;
    
        private String url;
    
        // Getters and Setters !!!
    }
    

提交回复
热议问题