Spring Boot: Multiple similar ConfigurationProperties with different Prefixes

后端 未结 4 999
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 07:45

I\'m using Spring Boot and have two very similar services which I\'d like to configure in my application.yml.

The configuration looks roughly like this:

4条回答
  •  灰色年华
    2020-12-29 08:19

    The @ConfigurationProperties anotation has the field to set prefix configulation. Here is my example:

    @Component
    @ConfigurationProperties(prefix = "b2gconfig")
    public class B2GConfigBean {
        private  String account;
    
        public String getAccount() {
            return account;
        }
    
        public void setAccount(String account) {
            this.account = account;
        }
    
        public String getKey() {
            return key;
        }
    
        public void setKey(String key) {
            this.key = key;
        }
    
        private  String key;
    }
    

    And my application.properties file:

提交回复
热议问题