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