不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2021-05-26 09:38:01  修改时间:2024-03-29 07:13:56  分类:Java框架/系统  编辑

在Spring中,可以通过propertityConfigurer类在配置文件中加入外部配置文件,同时也可以指定外部文件的编码方式

例如:

<!--引入jdbc.properties配置文件并设置该配置文件的编码方式-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>classpath:jdbc.properties</value>
    </property>
    <property name="fileEncoding">
        <value>UTF-8</value>
    </property>
</bean>

 

当然也可以同时引入多个配置文件:

<!--引入多个配置文件-->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:jdbc.properties</value>
            <value>classpath:ftl.properties</value>
            <value>/resourse/spring/*.properties</value>
        </list>
    </property>
</bean>

注意下,这里的<property name="locations">

如果写成了location,是不支持list多引入标签的

 

特别注意:一个项目,不要配置多个PropertyPlaceholderConfigurer类实例,详见问题:关于配置Spring框架的多个propertyConfigurer的问题