Here’s the scenario:
I have a standard applicationConfig.xml spring configuration for a basic web app. It works great. I also have a “core jar” for one of our internal dependencies for a different app. The “core jar” has an AnnotationConfigApplicationContext which registers the different @Configuration beans appropriately. I’m trying to use the annotation @Configuration beans in the app which is configured using the applicationConfig.xml.
I can dream up two options which I believe will work:
-
Refactor the xml config to also use the annotationConfig and register the different configurations to the context the same way our “core jars” do.
-
Create a second context and access it directly instead of having the singletons/prototypes live on the same applicationContext as the xml config. I’d really rather not do this as it seems more like a hack than an elegant solution (and I’m not entirely sure it would behave as I’d want it to.)
-
What I’m dreaming of, but can’t find any documentation to support
I’d like to register the annotation configuration bean into the application context somehow, but I can’t get the objects to line up the way I’d like them to (aka, my context won’t .register() the @Configuration file – only 1 bean at a time….)
Just to follow up – I got this working (YAY). In my case, I ended up following the general pattern set forth by gpeche.
The applicationContext-parent.xml contained the 1 bean def:
<bean id="parentApplicationContext" class="org.springframework.context.annotation.AnnotationConfigApplicationContext" scope="singleton">
<constructor-arg>
<list>
<value>com.package.CoreCommonInContainerConfigImpl</value>
<value>com.package.CoreCommonCommonConfigImpl</value>
</list>
</constructor-arg>
</bean>
where the CoreCommon****Impl classes are @Configuration annotated classes which define beans for that context.
As gpeche noted, an @Autowired Bean bean; inside of a controller (for example) falls back on the parent context and resolves automagically.
THANKS!