-
Jul 27th, 2007, 12:15 PM
#1
Child context not reflected in app context in an applicationcontext aware parent bean
I have a bean called CommandCreator which implements ApplicationcontextAware interface and returns beans of a particular type
public class CommandCreator implements ApplicationContextAware {
private ApplicationContext ctx ;
public void setApplicationContext....
public Command getCommandofType(String type){
return (Command) ctx.getBean("xxx");
}
}
this is configured in xml file as
a.xml
<beans>
<bean id="a" class=CommandCreator />
</beans>
I have another module that defines a set of commands as beans
commands.xml
<beans>
<bean id="xxx" class=XXXCommand />
<bean id="yyy" class=XXXCommand />
</beans>
Now since this an applciation with multiple ejbs, I use the ContextSingletonBeanFactoryLoactor to load these app context files.
beanRefContext.xml
<bean id="appContext" class="org.springfr......ClassPathXMLContext">
<constructor-arg>
<a.xml>
<commands.xml>
</constructor-arg>
</bean>
In my ejb, after I load the beanRefContext xml
when I do commandCreator.getCommandofType("xxx); I get an error tht bean with the name xxx is not been configured.
Is my understanding that since CommandCreator was configured as a bean in a.xml, the app context that was passed in its setApplicationContext only contains the beans defined in that xml file , and when the subsequent xml files are loaded (and contexts created for them),the top level app context thats been set is not updated, while the child app context set the parent app context as their parent.
And since I am asking a bean from a parent context , it would only look in itself and not in the children (which would have been reverse if you ask for a bean from a child context, it would inturn look at the parent context if it did not contain the defintion) and hence i get the bean not found exception.
Is the above understanding correct? If yes what is the recommended solution
would just changing the ordering of xmls in bean ref context work (would I get unsatisfied dependencies exception in that case ?), otherwise what are the possible reasons for this exception.
thanks
-Satish
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules