【发布时间】:2019-02-02 14:35:23
【问题描述】:
我有一个使用标准 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 而不是 other-spring-stuff.xml 的任何原因?它只是一个例子还是你重命名了文件?
-
我只是想让这个问题更加不言自明。实际文件是 spring.xml
-
你的 other-spring-stuff.xml 还在 src/main/resources 下吗?你能试试不带
/的classpath*:other-spring-stuff.xml吗 -
我决定删除项目并从主分支重新结帐。现在我的错误变成了
web.xml is missing and <failOnMissingWebXml> is set to true,就像这个未回答的问题一样:stackoverflow.com/questions/51385888/…
标签: spring eclipse maven classloader