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
posted
0
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
posted
0
HI,
ApplicationContext.xml is available to the ContextLoaderServlet but still i am getting the same error
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
posted
0
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..