Spring常用功能摘要

xml中读取properties文件

  1. 在Resource文件夹中创建配置database.properties文件
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/ims?useUnicode=true&characterEncoding=utf-8
user=root
password=xxxxxx
  1. 在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>

猜你喜欢

转载自www.cnblogs.com/neuhuang/p/12761797.html