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

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

FileNotFoundException

Maven项目,application-context.xml、db.properties文件均放置在src/main/resources目录下,
Tomcat部署项目,src/main/resources目录下的配置文件默认位置为:{项目名}/WEB-INF/classes,
而Spring却在项目根目录下寻找,肯定找不到,因此,配置时指定classpath目录下寻找即可。

解决方案如下:

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

posted @ 2021-10-15 15:11  水无黑白  阅读(159)  评论(0)    收藏  举报