Spring中引入其他配置文件

一、引入其他 模块XML  

在Spring的配置文件,有时候为了分模块的更加清晰的进行相关实体类的配置。比如现在有一个job-timer.xml的配置

在Spring的整体的配置文件中使用 <import resource="classpath*:/spring/job-timer.xml" />引入。

二、引入properties文件。

方法1:

    <!--引入数据库配置信息 -->
    <context:property-placeholder location="classpath*:properties/db.properties" />
方法2:

情况1配置一个:

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath*:db/jdbc.properties" />
    </bean>
情况2配置多个:

复制代码
    <bean id="propertyConfigure" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:/opt/demo/config/demo-db.properties</value> 
                <value>classpath:/opt/demo/config/demo-db2.properties</value> 
            </list>
        </property>
    </bean>

这些properties中就是key-value的键值对,使用的时候可以使用${xxx} 获取。

posted @ 2017-12-11 10:56  技术专家  阅读(287)  评论(0)    收藏  举报