xml中读取properties文件
- 在Resource文件夹中创建配置database.properties文件
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ims?useUnicode=true&characterEncoding=utf-8
user=root
password=xxxxxx
- 在application.xml中配置读取文件
<!-- 1、配置数据源 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:database.properties</value>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
</bean>