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>
相关推荐
hasty4 天前
policy.xml 在,不代表策略生效:ImageMagick 补丁给安全配置验收的提醒
xml·mysql·安全
泡海椒7 天前
JQuick-Excel JQuickRow 数据准备实战:JObjectConverter、JQuickRow.toRows 与 XML 导出链路
xml·windows·excel
泡海椒9 天前
JQuick-Excel 字段映射实战:用 MAPPING 固化 Excel 表头与业务字段契约
xml·java·开发语言·excel
执明wa22 天前
Android RecyclerView 多类型, 多种 Item
android·xml·开发语言·设计模式·android studio
wl851122 天前
SAP CPI 教程004 如何通过groovy修改XML节点属性值
xml
码匠许师傅24 天前
【C++三方组件】TinyXML2:两个文件的极简 XML 解析器
xml·c++
yuzhiboyouye25 天前
my-batisPlus什么时候用xml什么时候用mapper自带的方法,这两种写法专业一点叫什么,什么场景分别使用
xml
筝筝ba1 个月前
如何跳过FFDC
xml·linux·运维·服务器·网络
yuzhiboyouye1 个月前
那xml对应的sql语法,列举一下
xml·数据库·sql
筝筝ba1 个月前
OpenBMC 自动化测试中的多进程陷阱:从 Execute Process 返回异常到 output.xml 损坏问题分析
xml·linux·运维·服务器·网络