applicationContext classpath not found

Andrea Girardi picture Andrea Girardi · Apr 10, 2013 · Viewed 13.6k times · Source

For some reason (a shiro filter) I saved my application context file in WEB-INF folder. Everything works when I run tomcat but, when I try to get an application context from a controller using :

context = new ClassPathXmlApplicationContext(fileContext);

I receive always this exception:

IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

It seems that under ecplise I'm not able to include WEB-INF under classpath. I took a look to a lot questions here in stackoverflow but I didn't find yet a solution.

If I move the applicationContext.xml file under src/main/java folder, I'm able to get the context but, the shiro filder defined into web.xml file is not able to see the shiro bean defined under applicationContext file (I double checked and the bean is correctly worked). How can I tell to web.xml to get content from src/main/java? Or, how can I reach the applicationContext.xml

Answer

maggu picture maggu · Apr 10, 2013

WEB-INF is not in your CLASSPATH. WEB-INF/classes is. So why dont you put it in a source folder and package the application?