【Spring】引入properties属性文件

举例:

现在有一个属性文件-c3p0.perperties,如下所示

c3p0.driverClassName=com.mysql.cj.jdbc.Driver
c3p0.url=jdbc:mysql://localhost:3306/ssm?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
c3p0.username=root
c3p0.password=root

将上述属性文件引入applicationContext.xml

引入单个属性文件:

PropertyPlaceholderConfigurer写法

    <!-- 引入一个属性文件方法一 -->
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:c3p0.properties"></property>
    </bean>

context命名空间写法

    <!-- 引入一个属性文件方法二 -->
     <context:property-placeholder location="classpath:druid.properties" 
        /> 

引入多个属性文件:

复制代码
    <!-- 引入多个属性文件方法一 -->
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:c3p0.properties</value>
                <value>classpath:druid.properties</value>
            </list>
        </property>
    </bean>
复制代码

 

posted @   王广元  阅读(148)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
分享到:
点击右上角即可分享
微信分享提示