Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

get ref bean from applicationContext.xml

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ramesh kancherla
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is in the "Tomcat" logs? Do you see the applicationContext being created?

Mark
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic