• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

NoSuchBeanDefinitionException in Spring

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am doing the following -

I have a parent application bean context which does not construct any beans.

ApplicationBeanContext parent = new FileSystemXmlApplicationContext("empty.xml");

I have two children contexts, child1 and child2
ApplicationBeanContext child1 = new FileSystemXmlApplicationContext("child1.xml",parent);


Child1.xml

<bean id="child1" class="child1">
<property name="val">
<value>1</value>
</property>
</bean>

ApplicationBeanContext child2 = new FileSystemXmlApplicationContext("child2.xml",parent);
Child2.xml

<bean id="child2" class="child2">
<property name="child1">
<ref name="child1"/>
</property>
</bean>

(The code above is pseudo code)
Basically, I've configured child1 and child2 contexts to have the same parent. At child2's object initialisation, I get the following error

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'child1' is defined:

Is this because I'm giving the xml files to the child contexts and not the parent context? Is there any solution for this?

Thanks in advanace
- Neha.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you suppose Child2 is supposed to know anything about Child1?
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is this because I'm giving the xml files to the child contexts and not the parent context?


yeah...you have the answer ...
 
Neha Gap
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the replies

- Neha.
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!