aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "get ref bean from applicationContext.xml " Watch "get ref bean from applicationContext.xml " New topic
Author

get ref bean from applicationContext.xml

ramesh kancherla
Ranch Hand

Joined: May 01, 2008
Posts: 120
Hi,
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.

applicationContext.xml




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
Hi,

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
HI,

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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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

Mark


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

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
Greenhorn

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..
 
 
subject: get ref bean from applicationContext.xml
 
Similar Threads
Problem in configuring JNDI for Spring
NotWritablePropertyException,BeanCreationException
Spring MultiActionController methodNameResolver invalid property error
Tomcat + Spring + Hibernate: PropertyNotFoundException
Spring with Hibernate webapplication example on myeclipse IDE