0

My applicationContext is placed at path:src\main\webapp\WEB-INF\conf\applicationContext.xml

When I build this web application.I can see that conf folder is placed at {projectname.war}\WEB-INF\conf\applicationContext.xml.And Application works fine.

Now I happened to write a class with public static void main where I am trying to load applicationCOntext using below:

ApplicationContext context = new ClassPathXmlApplicationContext("../conf/applicationContext.xml");

ClassPathXmlApplicationContext("/WEB-INF/conf/applicationContext.xml"); ClassPathXmlApplicationContext("applicationContext.xml"); none of above seems to be working. error is listed below:

Caused by: java.io.FileNotFoundException: class path resource [../conf/applicationContext.xml] cannot be opened because it does not exist.

Can someone point what wrong I am doing ?

Rips
  • 1,964
  • 1
  • 23
  • 45
  • Why are you writing a class with a main method in a web application? `/WEB-INF` isn't part of the class path so trying to load it from the class path isn't going to work. Prefix with `file:` and then, depending on the location of your class, it might load. – M. Deinum Jun 09 '14 at 11:55
  • @M.Deinum was just trying to test some method in a java class in the src java folder.When I needed some beans I tried to load appContext which threw this error. – Rips Jun 09 '14 at 12:01
  • 1
    Why aren't you simply writing a jUnit test instead of a executable class? Saves you writing a lot of plumping and you can use springs resource loading and testing to make things easier. – M. Deinum Jun 09 '14 at 12:09
  • that is what I am doing now.thanks M. – Rips Jun 09 '14 at 12:16

0 Answers0