![](/img/trans.png)
[英]Spring inside war cannot find classpath resource in an inner jar file
[英]Spring cannot find file in classpath, but it's right there at the root of the war file
我有一個使用標准Maven Web應用程序布局的項目,該項目已部署在Eclipse Photon的Tomcat 8.5中(具有最新更新)。
在src\\main\\webapp\\WEB-INF\\applicationContext.xml
,有一個<import resource="classpath:/other-spring-stuff.xml" />
我驗證了通常位於src/main/resources
的other-spring-stuff.xml
,它出現在mvn install
生成的WAR
的根目錄中。
但是,當嘗試在Eclipse中的Tomcat中運行應用程序時,我得到:
20:37:17 SEVERE: Servlet [servletSpringDispatcher] in web application [/myapp] threw load() exception - 2018-08-27 @{org.apache.catalina.core.StandardContext loadOnStartup}
java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:227)
我真的不知道這是Maven,Eclipse還是Spring的問題。
是什么原因造成的? 實際上,這是在一個直到昨天還可以正常工作的項目中,並且項目配置沒有任何變化。
原始問題( 未找到spring.xml )和次要問題( 缺少web.xml的錯誤報告 )均已通過以下步驟解決:
.project
, .classpath
和.settings/
.project
, .classpath
和.settings/*
,然后將它們添加到.gitignore
我相信根本原因是,簽入倉庫中的這些特定於Eclipse的配置文件之一已損壞和/或與我的Eclipse版本不兼容。 另外: 這些文件似乎包含對工作空間中事物的絕對路徑引用,因此當簽出未經修改的項目到其他位置時,它們會中斷 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.