springfilenotfoundexceptioncontext-param

(Spring) class path resource exception java.io.FileNotFoundException


I have aded following code to my web.xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
    classpath:com/neelamhotel/mavenwebproject5/configs/dao-context.xml
</param-value>

But I am getting error for the same as

IOException parsing XML document from class path resource [com/neelamhotel/mavenwebproject5/configs/dao-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/neelamhotel/mavenwebproject5/configs/dao-context.xml] cannot be opened because it does not exist

Project Structure

enter image description here

Explorer View

enter image description here

I know dao-context.xml file is there. But then why it is giving an error ?

Updated Explorer view

enter image description here

Created WAR file view

enter image description here


Solution

  • In a Maven project, src/main/java is for Java source files. The other files are ignored by Maven.

    Resources (i.e. non-Java files) that must be copied and be available in the classpath must go in src/main/resources.

    Gradle uses the same conventions.