Spring @Configuration file with PropertyPlaceholderConfigurer bean doesn't resolve @Value annotation

后端 未结 3 826
没有蜡笔的小新
没有蜡笔的小新 2020-12-25 14:24

I have following configuration file:

@Configuration
public class PropertyPlaceholderConfigurerConfig {

    @Value(\"${property:defaultValue}\")
    private          


        
3条回答
  •  甜味超标
    2020-12-25 14:52

    If you run your application using VM option and then want to access that option in your application you have to do it slightly different:

    @Value("#{systemProperties.property}")
    private String property;
    

    Your PropertyPlaceholderConfigurer is not aware of system properties, also note that you are accessing properties using $ - which refers to place holders and # refers to beans, where systemProperties is a bean.

提交回复
热议问题