踩坑:
properties配置文件内,定义的key尽量避开关键字
如非要使用关键字,可在<context/> 加载配置文件时加 system-properties-mode=‘NEVER’,指定关闭系统属性加载
开启context命名空间
<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.xsd">
</beans>
使用context命名空间,加载指定的properties配置文件
标准基本加载
<context:property-placeholder location="classpath:jdbc.properties"/>
不加载系统属性
<context:property-placeholder location="classpath:jdbc.properties" system-properties-mode="NEVER"/>
同时加载多个properties文件
<context:property-placeholder location="jdbc.properties,msg.properties"/>
加载所有properties文件
<context:property-placeholder location="classpath:*.properties"/>
从类路径或者JAR包中搜索并加载properties文件
<context:property-placeholder location="classpath*:*.properties"/>
使用${ }读取加载的属性值
<property name="配置key" value="${jdbc.配置key}">