Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"

錯誤筆記之Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"

applicationContext 加載properties類型的配置文件的問題

錯誤信息

Could not resolve placeholder 'jdbc.driver' in string value "${jdbc.driver}"
  • 1

錯誤緣由

在配置文件中,使用2次引入配置文件的掃描,但是兩次掃描的key是一樣的,並不能進行兩次掃描

<context:property-placeholder location="classpath:config/resouce.properties"/>
<context:property-placeholder location="classpath:config/db.properties"/>
  • 1
  • 2

解決方法1

將配置文件寫到一個方法裏,用 “,” 隔開

<context:property-placeholder location="classpath:config/db.properties,classpath:config/resouce.properties"/>
  • 1

解決方法2

在每個掃描的配置文件後加上 ignore-unresolvable=”true”

<context:property-placeholder location="classpath:config/resouce.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:config/db.properties" ignore-unresolvable="true"/>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章