java.io.FileNotFoundException: Could not open ServletContext resource [/db.properties]

Maven项目,application-context.xml、db.properties文件均放置在src/main/resources目录下,Tomcat部署项目,src/main/resources目录下的配置文件默认位置为:

{项目名}/WEB-INF/classes,而Spring却在项目根目录下寻找,肯定找不到,因此,配置时指定classpath目录下寻找即可。
解决方案如下:
  在applicationContext,xml文件下配置
  <context:property-placeholder location="classpath:db.properties" />

原文地址:https://www.cnblogs.com/zhangzijun/p/11206559.html

时间: 2024-08-07 08:41:43

java.io.FileNotFoundException: Could not open ServletContext resource [/db.properties]的相关文章

nested exception is java.io.FileNotFoundException: Could not open ServletContext resource

<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> 注意这段配置尽量写在靠前的位置,因为在tomcat启动后web项目会先初始化上下文,我们这段配置正是指定了上下文配置的文件位置,在上下文初始化完成之后才应当继

出错: IOException parsing XML document from ServletContext resource [/cn.mgy.conig]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/cn.mgy.conig]

错误的详细内容: 严重: StandardWrapper.Throwable org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/cn.mgy.conig]; nested exception is java.io.FileNotFoundException: Could not open Se

Spring部署报错:Could not open ServletContext resource [/db.properties]

在使用Spring MVC过程中,部署项目报错,报错信息如下: 八月 15, 2016 5:02:04 下午 org.apache.catalina.core.StandardContext listenerStart严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.spring

Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be ope

1.错误描述 java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) at org.springframework.test.context.DefaultTestContext.

【c3p0】报错:java.io.FileNotFoundException: Resource not found at path &#39;/mchange-log.properties&#39;

配置项目启动初始,报错如下: 1 java.io.FileNotFoundException: Resource not found at path '/mchange-commons.properties'. 2 at com.mchange.v2.cfg.BasicPropertiesConfigSource.propertiesFromSource(BasicPropertiesConfigSource.java:64) 3 at com.mchange.v2.cfg.BasicMulti

cxf(3.1.1) 异常Caused by: java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml]

Caused by: java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist用的最新版本,这个版本中 cxf-extension-soap.xml 不需要了直接在配置文件中删除即可 现在只需要引两个文件 <import resource="classpath:META-INF/cxf/

java.io.FileNotFoundException: class path resource [XXXXX.xml] cannot be opened

java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exit. 在用maven管理的spring项目中做单元测试时候,加载不了spring的配置文件.出现该问题的原因是,用maven创建的项目,必须把spring的配置文件beans.xml或者applicationContext.xml放到系统根目录下,做单元测试时候用 ApplicationCon

解决CXF的java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist

以下是错误信息 九月 25, 2017 8:22:04 下午 org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh 信息: Refreshing Root WebApplicationContext: startup date [Mon Sep 25 20:22:04 CST 2017]; root of context hierarchy 九月 25, 2017 8:22:04 下午 or

java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist

java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist 异常如下: java.io.FileNotFoundException: class path resource [com/jxust/zjh/model/Account.hbm.xml] cannot be opened because it does not exist 在spring中我这样配置<pr