• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

path to applicationContext.xml

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a web app which is deployed on server. I can access the applicationContext by way which you can see bellow from a servlet.



Now I would like to access it by this way from other part same project:



My problem is I cannot access the xml file when it isn't in main/resources path. I need to have (and I have it there) this xml in main/webapp/WEB-INF.
I have tried different path to this xml but unsuccessully.


Could you help me ?
 
ranger
Posts: 17347
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
Use a prefix instead like "http:"

The ClassPathXmlApplicationContext default loading mechanism is to look from the root of the classpath. You cannot go below the root like you are trying to do.

But you can override the default loading mechanism for a resource/file by using a prefix for it. Either "classpath:", "http:" or "file:"

So for your code

ApplicationContext ctx = new ClassPathXmlApplicationContext("../webapp/WEB-INF/applicationContext.xml");

change it to

ApplicationContext ctx = new ClassPathXmlApplicationContext("http:WEB-INF/applicationContext.xml");

But to be honest in a web environment it is much cleaner to just use the ContextLoaderListener and WebApplicationContextUtils

Mark

Mark
 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for your reply and sorry for my late one.

I would like to use this context access only for testing purposes.

I have in web.xml


And if I use your code from main method:


then I get this exceptions:


Do you have any idea why it is not working for me?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic