The PropertySourcesPlaceholderConfigurer
object is a BeanFactoryPostProcessor
, so, according to the Spring documentation:
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
.
By marking this method as static, it can be invoked without causing
instantiation of its declaring @Configuration
class, thus avoiding the
above-mentioned lifecycle conflicts. Note however that static @Bean
methods will not be enhanced for scoping and AOP semantics as
mentioned above. This works out in BFPP cases, as they are not
typically referenced by other @Bean
methods. As a reminder, a
WARN-level log message will be issued for any non-static @Bean
methods
having a return type assignable to BeanFactoryPostProcessor
.