It seems your configuration class contains some BeanFactoryPostProcessor
. I beleive it is PropertySourcesPlaceholderConfigurer
as you need this bean to have properties resolved.
Some explanation from Spring javadoc:
Special consideration must be taken for @Bean methods that return Spring BeanFactoryPostProcessor (BFPP) types. Because BFPP objects must be instantiated very early in the container lifecycle, they can interfere with processing of annotations such as @Autowired, @Value, and @PostConstruct within @Configuration classes. To avoid these lifecycle issues, mark BFPP-returning @Bean methods as static.
That is why @Autowired
and @Value("#{systemProperties['your.system.property']}")
don't work within the config class.
So to solve your issue just make method that returns
PropertySourcesPlaceholderConfigurer
static or add such method if you don't have it
@Bean
public static PropertySourcesPlaceholderConfigurer pspc() {
return new PropertySourcesPlaceholderConfigurer();
}
And make sure that there is no more non-static BFPP-returning @Bean methods.
Also you can move BFPP beans to separate @Configuration
class.
UPDATE
Simple app demonstrating usage of
@Value
within
@Configuration
@Configuration
public class SimpleJavaConfig {
@Value("${java.version}")
private String property;
public static void main(String[] args) throws IOException {
ApplicationContext app = new AnnotationConfigApplicationContext(SimpleJavaConfig.class);
System.out.println("|" + app.getBean("propertyBean") + "|");
}
@Bean
public static PropertySourcesPlaceholderConfigurer pcc() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
public String propertyBean() {
return property;
}
}