user2274060
user2274060

Reputation: 904

java.io.FileNotFoundException: [WEB-INF/spring-servlet.xml] cannot be opened because it does not exist

In/src/main/java/com/application/myGoogleAppEngine/controller/AddressController.java, I want to use this instructions for using the beans by after :

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/WEB-INF/spring-servlet.xml");

My spring-servlet.xml file sits in /src/main/webapp/WEB-INF/ directory.

When I execute my spring application, I've the following error :

java.io.FileNotFoundException: class path resource [WEB-INF/spring-servlet.xml] cannot be opened because it does not exist

In my memories, I know that we can use a function to obtain the current directory of the project but I don't remember.

Otherwise, do you have any solutions ?

Thank you

Upvotes: 2

Views: 8629

Answers (3)

nirmal kumar
nirmal kumar

Reputation: 1

you can check the web.xml location. If this is not correct it will throw an error.

you can check in properties of the project: please see in the attached image

[1]: https://i.sstatic.net/dLwsi.png

Upvotes: 0

arjun kumar
arjun kumar

Reputation: 545

use this way

new ClassPathXmlApplicationContext( "classpath*:**/servlet.xml")

This will search whole WEB-INF folder for given name

Upvotes: 1

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279890

The WEB-INF directory is not typically put on the classpath. Therefore you won't be able to get anything within it as a resource, ie. what ClassPathXmlApplicationContext is trying to do.

Put your spring-servlet.xml in a directory that is put on the classpath, ie. WEB-INF/classes.

Upvotes: 6

Related Questions