I have a class annotated with @Configuration
(let's call it StubConfiguration
) which has a single method that is annotated with @Bean
. This method returns a BeanFactoryPostProcessor
implementation which is responsible for registering some beans. However, Spring is unable to resolve the beans this factory registers at runtime.
My assumption is that StubConfiguration
is picked up by Spring's component scanning, the BeanFactoryPostProcessor
is registered and then its postProcessBeanFactory()
method is invoked, subsequently registering the beans I need.
Am I thinking about this incorrectly? How can I go about registering the beans that I need with my ApplicationContext
using this post processing?
If you're also using an XML app context to declare beans, you can tell Spring to do a component scan and treat @Stub
as a Spring component annotation.
<context:component-scan base-package="your.base.package">
<context:include-filter type="annotation" expression="your.stub.package.Stub"/>
</context:component-scan>
If you're only using an annotation config app context, check out this answer for a way to do it without XML.