Spring Property Injection in a final attribute @Value - Java

别来无恙 提交于 2019-11-30 04:19:47

The only way you can inject values into a final field is through Constructor Injection. Everything else would be an awful hack on Spring's side.

Austin Poole

If you are looking for an example here is one:

public class Test {
    private final String value;

    public Test(@Value("${some.value}") String value){
        this.value=value;
        System.out.println(this.value);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!