簡體   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