0

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

Meena Chaudhary
  • 9,909
  • 16
  • 60
  • 94

1 Answers1

2

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.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • I have moved `dao-context.xml` to src/main/resources/. And changed the `param-value` as `src/main/resources/dao-context.xml`. But stil getting file not found error – Meena Chaudhary Aug 16 '15 at 13:47
  • You don't need to change anything to your spring configuration. What you put in src/main/resources ends up in the classpath. Use the same package structure as what you have now, but inside src/main/resources instead of src/main/java. – JB Nizet Aug 16 '15 at 13:50
  • I moved my package inside `resources` and kept the `param-value` to `classpath:com/neelamhotel/mavenwebproject5/configs/dao-context.xml`. But unfortunately still getting file not found error. confusing !!! – Meena Chaudhary Aug 16 '15 at 14:09
  • Have you rebuilt and redeployed the webapp? Post an updated explorer view. Check that the file can be found in war file built by Maven, under WEB-INF/classes. – JB Nizet Aug 16 '15 at 14:15
  • Everything seems OK. If starting the server from eclipse, try stopping it, cleaning its work directory, and starting it again. Also try dropping the war file in the web server and starting it from outside eclipse. – JB Nizet Aug 16 '15 at 14:30
  • Great , it is working now. Thanks for walking me through. – Meena Chaudhary Aug 16 '15 at 14:36