Announcement Announcement Module
No announcement yet.
Child context not reflected in app context in an applicationcontext aware parent bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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


    <bean id="a" class=CommandCreator />

    I have another module that defines a set of commands as beans

    <bean id="xxx" class=XXXCommand />

    <bean id="yyy" class=XXXCommand />


    Now since this an applciation with multiple ejbs, I use the ContextSingletonBeanFactoryLoactor to load these app context files.


    <bean id="appContext" class="org.springfr......ClassPathXMLContext">

    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.


  • #2
    The context loaded by ContextSingletonBeanFactoryLoactor is the parent context of the other one. So your CommandCreator should actually have access to the other beans. Maybe there is something wrong with the setup of the parent context. Is it really initialized? Are xxx and yyy instantiated?