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

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

I have following configuration file:

@Configuration
public class PropertyPlaceholderConfigurerConfig {

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


        
3条回答
  •  感情败类
    2020-12-25 15:01

    For any other poor souls who couldn't get this to work in some Configuration classes when they work in others:

    Look to see what other beans you have in that class and if any of them get instantiated early in the ApplicationContext. A ConversionService is an example of one. This would instantiate the Configuration class before what is required is registered, thereby making no property injection take place.

    I fixed this by moving the ConversionService to another Configuration class that I Imported.

提交回复
热议问题