eclipsespringmaveneclipse-jeerunjettyrun

Spring/Maven project in Eclipse JEE: applicationContext.xml cannot be opened


Having received a Spring/Maven project, I:

PROBLEM: It does not found its own applicationContext.xml even though it is present in src/main/webapp/WEB-INF/classes/applicationContext.xml.

16:58:58.183 [main] ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: 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

QUESTION: How can I tell Eclipse JEE where applicationContext.xml is, or otherwise fix this?


Solution

  • WEB-INF/classes is a directory created by the Maven war plugin when it builds the war, it should not be a project folder. The Maven war plugin will create it for any war project so it can put compiled classes and resources there that live in your src/main/java and src/main/resources folders as per the standard Maven conventions.

    Similarly, the WEB-INF/lib is automatically created by the war plugin and filled with the dependencies of your war module that are not scoped as provided.

    So put the file (and any other file you now have in src/main/webapp/classes) in the src/main/resources folder of your war module and it should work as expected.

    Side note: this is only for the classes and lib subdirectories; it is perfectly valid to have a WEB-INF folder in your project so you can add files (say: web.xml) that need to go inside WEB-INF there.