• 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
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 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
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?
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic