Property values in bean class are null in constructor

前端 未结 2 612
逝去的感伤
逝去的感伤 2020-12-19 11:01

I\'m trying to use values from my application.properties file in my service implementation class/bean. But when the bean is initialized through my config class, the property

2条回答
  •  忘掉有多难
    2020-12-19 11:48

    Those values are injected after the instance is created. So they are null in the constructor.

    To execute a method after the values are injected use @javax.annotation.PostConstruct:

    @PostConstruct
    public void init(){ // method name doesn't matter
         functionOne(value_one, value_two, value_three);
    }
    

提交回复
热议问题