簡體   English   中英

Spring在類路徑中找不到文件,但是它在war文件的根目錄中

[英]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/resourcesother-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的錯誤報告 )均已通過以下步驟解決:

  1. 從工作空間中刪除項目,但將其保留在文件系統上
  2. 轉到項目的文件系統位置,然后刪除.project.classpath.settings/
  3. 將項目重新導入Eclipse,選擇Existing Maven Project作為項目類型
  4. 為了防止再次出現:從git中刪除.project.classpath.settings/* ,然后將它們添加到.gitignore

我相信根本原因是,簽入倉庫中的這些特定於Eclipse的配置文件之一已損壞和/或與我的Eclipse版本不兼容。 另外: 這些文件似乎包含對工作空間中事物的絕對路徑引用,因此當簽出未經修改的項目到其他位置時,它們會中斷

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM