0

I have a project using the standard Maven web app layout, deployed within Tomcat 8.5 in Eclipse Photon (with latest updates).

Inside of src\main\webapp\WEB-INF\applicationContext.xml, there is an <import resource="classpath:/other-spring-stuff.xml" />

I verified the other-spring-stuff.xml which is normally sitting in src/main/resources, appears in the root of the WAR generated by mvn install.

But when trying to run the app in Tomcat within Eclipse, I get:

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)

I don't really know whether this is a problem with Maven, Eclipse, or Spring.

What can cause this? This is actually in a project that was working fine until yesterday, and nothing changed on the project configuration.

Alex R
  • 11,364
  • 15
  • 100
  • 180
  • any reason why is it looking for spring.xml instead of other-spring-stuff.xml? is it just an example or did u rename the file? – Jayesh Aug 28 '18 at 04:06
  • I was just trying to make it more self-explanatory for the question. The actual file is spring.xml – Alex R Aug 28 '18 at 04:08
  • your other-spring-stuff.xml is still under src/main/resources? can you try the `classpath*:other-spring-stuff.xml` without the `/` – Jayesh Aug 28 '18 at 04:14
  • I decided to delete the project and re-checkout from the master branch. Now my error changed to `web.xml is missing and is set to true`, as in this unanswered question: https://stackoverflow.com/questions/51385888/why-i-am-getting-error-web-xml-is-missing-and-failonmissingwebxml-is-set-to-t – Alex R Aug 28 '18 at 04:38
  • answered here https://stackoverflow.com/questions/31835033/web-xml-is-missing-and-failonmissingwebxml-is-set-to-true – Jayesh Aug 28 '18 at 04:44
  • NOT answered there. That question (31835033) deals with an actual missing web.xml. More like the other question I linked (51385888), mine is not actually missing. – Alex R Aug 28 '18 at 04:53
  • Attach the web.xml.Also check your eclipse deployment assembly – Raja Ramachandran Aug 28 '18 at 05:31

1 Answers1

1

The original problem (spring.xml not found) and secondary problem (false report of missing web.xml) were both resolved by taking the following steps:

  1. Delete the project from the workspace, but keep it on the file system
  2. Go to the project's filesystem location and delete .project, .classpath, and .settings/
  3. Re-Import the project into Eclipse, select Existing Maven Project as project type
  4. To prevent reocurrence: remove .project, .classpath, and .settings/* from git and then add them to .gitignore

I believe the root cause is that one of these Eclipse-specific config files that was checked into the repo had become corrupted and/or incompatible with my version of Eclipse. Also: these files seem to contain absolute-path references to things in the workspace, so they break when the project is checked out unmodified to a different location.

Alex R
  • 11,364
  • 15
  • 100
  • 180