Injecting Properties using Spring & annotation @Value

后端 未结 2 457
小鲜肉
小鲜肉 2020-12-15 09:29

I am trying to load a properties file into a Spring bean and then inject that bean into a class.

The only part I can\'t get to work seems to be using the @Resourc

2条回答
  •  独厮守ぢ
    2020-12-15 09:38

    Just one more solution using properties placeholder.

    The spring context:

    
    
        
    
        
    
    
    

    The java class where you want inject properties values:

    public class ClassWithInjectedProperty {
    
        @Value("${props.foo}")
        private String foo;
    }
    

提交回复
热议问题