xml文件如何加载properties文件(spring容器加载properties文件)

目的:把jdbc.properties文件加载进applicationContext.xml文件当中

resource文件目录下的applicationContext.xml文件

XML 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd">
    <!-- 在这里配置bean -->


</beans>

以上为默认生成的内容。

主命名空间为:

XML 复制代码
xmlns="http://www.springframework.org/schema/beans"

操作:

XML 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation=
               "http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context.xsd">

<!--    加载外部的properties文件-->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <!-- 在这里配置bean -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driver}"></property>
    <property name="jdbcUrl" value="${jdbc.url}"></property>
    <property name="user" value="${jdbc.username}"></property>
    <property name="password" value="${jdbc.password}"></property>
</bean>

</beans>
相关推荐
前网易架构师-高司机3 天前
带标注的山体滑坡塌方数据集数据集,识别率78.1%,974张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·自然灾害·山体滑坡
程序媛kelly3 天前
.xml / .jrxml 文件怎么打开?OpenFiles 实测预览、编辑、搜索与 AI 摘要排查流程
xml·人工智能·jrxml
潘潘的嵌入式日记4 天前
改完Keil工程文件被缓存覆盖?——uvprojx编辑的进阶四坑
xml·嵌入式·keil·调试·mdk·工程文件
Full Stack Developme4 天前
Flowable XML标签大全
xml
C137的本贾尼4 天前
第九篇:微服务与分布式——把一个大系统拆成多个小服务
xml·spring boot·后端
JustNow_Man7 天前
【Claude Code】 中给 Python + XML 项目建立可靠验证体系
xml·linux·python
AI产品实战8 天前
Gradle打包生成dependencies.xml详解
xml·java·gradle
斯特凡今天也很帅10 天前
xml页面可以打开,不报错,但是显示数据的地方也不显示,我是怎么解决的
xml·vue.js
前网易架构师-高司机10 天前
带标注的21种中药材识别数据集,识别率73.8%数据集,2237张图,支持yolo,coco json,voc xml,文末有模型训练代码
xml·yolo·json·数据集·中药·药材·中草药