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>
相关推荐
微微1笑抽了筋3 天前
xml中设置透明度
xml
Source.Liu3 天前
【Uppsala】入口模块(lib.rs)
xml·rust
Source.Liu3 天前
【Uppsala】介绍
xml·rust
Wang's Blog4 天前
AI Agent白手起家37: LangChain 输出解析器实战:文本、JSON、XML 与 Pydantic
xml·langchain·json
initialize13064 天前
Oracle数据库 binary XML data类型同步
xml·数据库
御坂嘀喵 白日焰火4 天前
LINQ之路18:LINQ to XML之导航和查询
xml·solr·linq
残月心殇 请珍惜枸4 天前
LINQ之路17:LINQ to XML之X-DOM介绍
xml·solr·linq
x17388062737 天前
XXE外部实体注入
xml·笔记
云水一下8 天前
零基础玩转bWAPP靶场(三十):XML/XPath 注入(登录表单)
xml·web安全·bwapp
云水一下9 天前
零基础玩转bWAPP靶场(三十一):XML/XPath 注入(搜索)
xml·web安全·bwapp