Spring Boot application.properties value not populating

后端 未结 8 548
孤街浪徒
孤街浪徒 2020-12-04 11:41

I have a very simple Spring Boot app that I\'m trying to get working with some externalised configuration. I\'ve tried to follow the information on the spring boot documenta

8条回答
  •  离开以前
    2020-12-04 12:16

    Actually, For me below works fine.

    @Component
    public class MyBean {
    
       public static String prop;
    
       @Value("${some.prop}")
       public void setProp(String prop) {
          this.prop= prop;
       }
    
       public MyBean() {
    
       }
    
       @PostConstruct
       public void init() {
          System.out.println("================== " + prop + "================== ");
       }
    

    }

    Now whereever i want, just invoke

    MyBean.prop

    it will return value.

提交回复
热议问题