Announcement Announcement Module
Collapse

JavaConfig forum decommissioned in favor of Core Container

As described at

http://static.springsource.org/sprin...fig/README.TXT

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

http://static.springsource.org/sprin...tml#beans-java

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at

http://forum.springsource.org/forumdisplay.php?f=26
See more
See less
Bean not found in parent context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean not found in parent context

    I'm using a hierarchical application context consisting of two xml files: appcontext-master.xml and appcontext-child.xml. The appcontext-master.xml is set as the parent of appcontext-child.xml as follows:

    ClassPathXmlApplicationContext contextMaster = new ClassPathXmlApplicationContext( "META-INF/appcontext-master.xml" );

    ClassPathXmlApplicationContext contextChild = new ClassPathXmlApplicationContext( "META-INF/appcontext-child.xml" );
    contextChild.getBeanFactory().setParentBeanFactory ( contextMaster );

    In appcontext-child.xml, I'm using ConfigurationPostProcessor to load a @Configuration class. In that @Configuration class, I have a @Bean method that creates a bean that has a dependency on a bean declared in appcontext-master.xml. My @Configuration class extends ConfigurationSupport and I'm calling getBean("masterBean") to get a reference to the bean in appcontext-master.xml. This, however, doesn't work. I get a "No bean named 'masterBean' defined" exception.

    I'm able to access beans in appcontext-child.xml just fine from that @Bean method, but accessing beans that reside in appcontext-master.xml result in the exception being thrown.

    Would appreciate any pointers on how I can get around this problem.

  • #2
    Resolved: Bean not found in parent context

    I got this resolved. The @Bean method did not have the Lazy=TRUE attribute and this was causing it to get instantiated prior to the setParentBeanFactory() call.

    Comment


    • #3
      thanks... got the same problem and you just gave me a solution..
      corporate recognition awards
      tedisco for Congress

      Comment

      Working...
      X