get ref bean from applicationContext.xml
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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
Posts: 124
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
What is in the "Tomcat" logs? Do you see the applicationContext being created?
Mark
Mark
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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
Posts: 3
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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..
ref bean="<bean id in applicationContext.xml>".
Apologies for the hasty post..
| Did you miss me? Did you miss this tiny ad? The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








