This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Other Application Frameworks and the fly likes get ref bean from applicationContext.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "get ref bean from applicationContext.xml " Watch "get ref bean from applicationContext.xml " New topic

get ref bean from applicationContext.xml

ramesh kancherla
Ranch Hand

Joined: May 01, 2008
Posts: 120
This is Ramesh. I am implementing Spring Application.I have register userDAO bean in applicationContext.xml and i am using this userDAO bean ref in Dispatcher-servlet.xml . But I am getting Exception.


and Dispatcher-servlet.xml is

I am getting Exception Trace as

can any one please give me suggestion how can I get userDAO ref from applicationContext.xml to dispatcher-servlet.xml

Thanks & Regards
Ramesh K
Anadi Misra
Ranch Hand

Joined: Jun 03, 2008
Posts: 69

Check the web.xml configuration for ContextLoaderListener or the ContextLoaderServlet what ever you are using, it moght be the applicationContext is not available to the container.

Anadi Mishra.
ramesh kancherla
Ranch Hand

Joined: May 01, 2008
Posts: 120

ApplicationContext.xml is available to the ContextLoaderServlet but still i am getting the same error

can you please tell me what is the problem

Thanks & Regards
Ramesh K
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17249

What is in the "Tomcat" logs? Do you see the applicationContext being created?


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Vasan Varadarajan

Joined: May 23, 2008
Posts: 3
I have the same issue, and tried a 'workaround':
Make your controller implement ApplicationContextAware. This causes the method:
public void setApplicationContext(ApplicationContext applicationContext)

to be called with the ApplicationContext object.
You can then use this to access the bean defined in applicationcontext.xml:

Example (method in controller):
public void setApplicationContext(ApplicationContext applicationContext) {
AppBean = (<Name of class> applicationContext.getBean("<id of bean in applicationContext.xml");

I admit that this is not a great workaround, since you probably want the bean to be injected into the constructor the controller. I think that the proper solution is with the 'ref' attribute in the controller bean specification. Somehow this ref attribute should be able to reference a bean in the applicationContext. If you find the answer let me know.
Vasan Varadarajan

Joined: May 23, 2008
Posts: 3
The previous workaround is not necessary. I was able to reference the application context bean in my -servlet.xml file the normal way:
ref bean="<bean id in applicationContext.xml>".
Apologies for the hasty post..
I agree. Here's the link:
subject: get ref bean from applicationContext.xml
Similar Threads
Tomcat + Spring + Hibernate: PropertyNotFoundException
Spring with Hibernate webapplication example on myeclipse IDE
Problem in configuring JNDI for Spring
Spring MultiActionController methodNameResolver invalid property error