Spring基礎之載入外部檔案
阿新 • • 發佈:2021-07-10
一、用註解載入(@PropertySource)
@PropertySource(value = { "classpath:jdbc.properties" },ignoreResourceNotFound = true) public class ApplicationCongfig { }
- ignoreResourceNotFound boolean值,預設是false,含義是如果找不到檔案是否將其忽略,在預設情況在找不到檔案或丟擲異常。
- name 配置這次屬性的名稱。
- value 字元創陣列,可以配置多個屬性檔案。
二、通過Xml配置檔案載入
<?xml version="1.0" encoding="UTF-8"作者:?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"> <!--掃描加註解的包 --> <context:component-scan base-package="cn.bzu.springpractice"></context:component-scan> <!-- 載入外部檔案 --> <context:property-placeholder ignore-resource-not-found="false" location="classpath:jdbc.properties"/> </beans>
-------------------------------------------
個性簽名:獨學而無友,則孤陋而寡聞。做一個靈魂有趣的人!
如果覺得這篇文章對你有小小的幫助的話,記得在右下角點個“推薦”哦,博主在此感謝!
萬水千山總是情,打賞一分行不行,所以如果你心情還比較高興,也是可以掃碼打賞博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!