Spring 加载配置文件

 <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>

示例:

    <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>

猜你喜欢

转载自augustcoco.iteye.com/blog/2216718