File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Bean from another application context to be referred in my application context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Bean from another application context to be referred in my application context" Watch "Bean from another application context to be referred in my application context" New topic
Author

Bean from another application context to be referred in my application context

Swathi Kodeboyina
Greenhorn

Joined: Jul 31, 2012
Posts: 7
I have two application context files. I want to refer a bean in first application context in the second application context. When I do this, I am getting a NoSuchBeanDefintionException.

How do I go about it?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1648
    
    7

Depends on the relationship between your contexts. If there is a parent child relationship that the child can see the parent but not vice versa. Assuming the beans are in the same context (not the same as the same .xml file) then you should be able to just use



from the reference docs

Specifying the target bean through the bean attribute of the <ref/> tag is the most general form, and
allows creation of a reference to any bean in the same container or parent container, regardless of whether
it is in the same XML file. The value of the bean attribute may be the same as the id attribute of the
target bean, or as one of the values in the name attribute of the target bean.


Alternatively if your second second application context is just a new file you created to split things up you will need to import it.


[How To Ask Questions][Read before you PM me]
deepu sharma
Greenhorn

Joined: Jul 28, 2009
Posts: 8
what exact requirement do you want? you want to refer bean in two applicaton contexts?
or one by one you wanna refer?
and also send full stack trace?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Bean from another application context to be referred in my application context