spring加载properties文件(xml)
spring加载properties文件
1、开启context命名空间,添加以下三行
xmlns:context="http://www.springframework.org/schema/context
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
2、使用context命名空间加载所有properties文件
<!-- 不加载系统属性-->
<!-- <context:property-placeholder location="jdbc.properties" system-properties-mode="NEVER"/>-->
<context:property-placeholder location="classpath*:*.properties"/>
3、使用属性占位符${}读取properties文件中的属性
<bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
还没有评论,来说两句吧...