Spring @Bean and PropertyPlaceHolderConfigurer | Java Code Geeks
However, after adding in the Property resolver, the test still fails, this time the value returned by the sampleService is null, not even the placeholder value!
The reason for the issue it turns out, is that with @Configuration which internally uses annotations like @Autowired, @Value, and @PostConstruct, any BeanFactoryPostProcessor beans have to be declared with a static, modifier. Otherwise the containing @Configuration class is instantiated very early and the BeanPostProcessors responsible for resolving annotations like @Value, @Autowired etc, cannot act on it.
Read full article from Spring @Bean and PropertyPlaceHolderConfigurer | Java Code Geeks
No comments:
Post a Comment