Spring deployment error: Could not open ServletContext resource [/db.properties]

In the process of using Spring MVC, the deployment project reports an error, and the error message is as follows:

Agu 15, 2016 5:02:04 PM org.apache.catalina.core.StandardContext listenerStart
warning: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/db.properties]
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)
…….
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/db.properties]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:153)
… 51 more

………………………………………….. ………………………………………….. ………………………………………….. …………………….

For the Maven project, the application-context.xml and db.properties files are all placed in the src/main/resources directory. For the Tomcat deployment project, the default location of the configuration file in the src/main/resources directory is: {project name}/WEB-INF /classes, but Spring looks for it in the root directory of the project, and it is definitely not found. Therefore, you can find it in the classpath directory when configuring it.

The solution is as follows:

<context:property-placeholder location=”classpath:db.properties” />


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *