简体   繁体   中英

applicationContext classpath not found

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

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?

use

context = new FileSystemXmlApplicationContext(fileContext);

instead of

context = new ClassPathXmlApplicationContext(fileContext);

Do not create an instance of ApplicationContext in your controller. The spring DispatcherServlet already creates one for you. All you need to do is access all bean declarations in you application context file using @Autowired .

Problem has been solved moving all configuration file under WEB-INF/classes and adding the prefix classpath:

<import resource="classpath:spring-data.xml"/> 

thanks to all for the help! I really appreciate that!

cheers, Andrea

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM