载入方式一:
<?xmlversion="1.0"encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jee="http://www.springframework.org/schema/jee"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"> <context:property-placeholderlocation="classpath:uc.properties"/> </beans>
载入方式二:
<?xmlversion="1.0"encoding="UTF-8"?> <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jee="http://www.springframework.org/schema/jee"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"> <beanid="configBean"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <propertyname="locations"> <value>uc.properties</value> </property> </bean> </beans>
使用方式:
<value>${name}</value> 或者 <propertyname="driverClass"value="${driverClass}"/>
如果有多个properties文件的情况
<beanid="configBean"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <propertyname="locations"> <list> <value>hello.properties</value> <value>welcome.properties</value> <value>other.properties</value> </list> </property> </bean>原文链接:https://www.f2er.com/xml/297932.html