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" />

posted @ 2019-07-18 12:41  番茄汤  阅读(1436)  评论(0编辑  收藏  举报