---
title: "Spring 加载配置文件"
author: "augustcoco"
date: "2015-06-03T16:59:29Z"
tags: []
categories: ["编程语言"]
slug: "spring"
draft: false
lastmod: "2015-06-03T16:59:29Z"
id: 2216718
url: "https://augustcoco.iteye.com/blog/2216718"
---

```java

 <bean id="propertyConfigurer"       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:com/starxing/test/database.properties</value>
        </property>
       <!-- 使用locations属性定义多个配置文件
       <property name="locations">
            <list>
                <value>classpath:config/mail.properties</value>
                <value>classpath:config/database.properties</value>
            </list>
      </property>
     -->
</bean>

```

示例：

```java


    <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="url">
                <value>${database.url}</value>
            </property>
            <property name="driverClassName">
                <value>${database.driver}</value>
            </property>
            <property name="username">
                <value>${database.user}</value>
            </property>
            <property name="password">
                <value>${database.password}</value>
            </property>
    </bean>


```