繁体   English   中英

找不到applicationContext类路径

[英]applicationContext classpath not found

出于某种原因(四郎过滤器),我将应用程序上下文文件保存在WEB-INF文件夹中。 当我运行tomcat时,一切正常,但是,当我尝试使用以下方法从控制器获取应用程序上下文时:

context = new ClassPathXmlApplicationContext(fileContext);

我总是收到以下异常:

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

似乎在ecplise下,我无法在类路径下包含WEB-INF。 我在stackoverflow上查看了很多问题,但没有找到解决方案。

如果将applicationContext.xml文件移到src / main / java文件夹下,则可以获取上下文,但是,定义到web.xml文件中的shiro filder无法看到在applicationContext文件下定义的shiro bean(我将检查,并且Bean正常工作)。 如何告诉web.xml从src / main / java获取内容? 或者,如何到达applicationContext.xml

WEB-INF不在您的CLASSPATH中。 WEB-INF / classes是。 那么,为什么不将其放在源文件夹中并打包应用程序呢?

使用

context = new FileSystemXmlApplicationContext(fileContext);

代替

context = new ClassPathXmlApplicationContext(fileContext);

不要在控制器中创建ApplicationContext的实例。 春天的DispatcherServlet已经为您创建了一个。 您需要做的就是使用@Autowired访问应用程序上下文文件中的所有bean声明。

解决了将所有配置文件移至WEB-INF / classes下并添加前缀classpath的问题已解决:

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

感谢大家的帮助! 我非常感谢!

干杯,安德里亚

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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