util:properties和context:property-placeholder标签都可以用来获取外部配置文件中的内容 
1、util:properties 
它是以声明bean方式来使用,创建了一个bean,下面使用的时候通过SpEL表达式#{}获取bean的属性。

<util:properties id="config" location="classpath:db.properties" />
<!-- 配置连接池 -->
<bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="#{config.driver}" />
<property name="url" value="#{config.url}" />
<property name="username" value="#{config.username}" />
<property name="password" value="#{config.password}" />
</bean>

需要注意,这种方式需要在spring配置文件头部声明

xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"

2、context:property-placeholder 
它是将配置文件加载至spring上下文中,然后通过${}取得值,常用于bean的属性上

<context:property-placeholder location="classpath:general.properties"/>
<!-- 配置Druid连接池 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<!-- 基本属性 driverClassName、url、user、password -->
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>

spring配置文件中util:properties和context:property-placeholder的更多相关文章

  1. 配置文件中取值: spring配置文件中util:properties和context:property-placeholder

    转载大神 https://blog.csdn.net/n447194252/article/details/77498916 util:properties和context:property-plac ...

  2. spring 配置文件中使用properties文件 配置

    配置Bean载入properties文件: <bean id="propertyPlaceholderConfigurer" class="org.springfr ...

  3. Spring依赖注入的方式、类型、Bean的作用域、自动注入、在Spring配置文件中引入属性文件

    1.Spring依赖注入的方式 通过set方法完成依赖注入 通过构造方法完成依赖注入 2.依赖注入的类型 基本数据类型和字符串 使用value属性 如果是指向另一个对象的引入 使用ref属性 User ...

  4. Spring 源码(4)在Spring配置文件中自定义标签如何实现?

    Spring 配置文件自定义标签的前置条件 在上一篇文章https://www.cnblogs.com/redwinter/p/16165274.html Spring BeanFactory的创建过 ...

  5. 在spring配置文件中引入外部properties配置文件 context:property-placeholder

    在spring的配置文件中,有时我们需要注入很多属性值,这些属性全都写在spring的配置文件中的话,后期管理起来会非常麻烦.所以我们可以把某一类的属性抽取到一个外部配置文件中,使用时通用spring ...

  6. 通过Spring配置文件中bean中的property赋值

    基本数据类型赋值-通过spring配置文件中bean中的property 扩展-以此方式可以通过配置为连接数据的属性赋值 1.如果是基本数据类型,可以通过setter方法为对象中的属性设置初始值,应用 ...

  7. JdbcTemplae使用入门&&Spring三种连接池配置&&Spring配置文件引用外部properties文件

    JdbcTemplate的使用 Spring为了各种支持的持久化技术,都提供了简单操作的模版和回调. JdbcTemplate 简化 JDBC 操作HibernateTemplate 简化 Hiber ...

  8. Spring配置文件中的parent与abstract

    在看项目的Spring配置文件时,发现消息队列的配置采用了继承方式配置Bean,在这梳理总结一下. 其实在基于spring框架开发的项目中,如果有多个bean都是一个类的实例,如配置多个数据源时,大部 ...

  9. Spring bean中的properties元素内的name 和 ref都代表什么意思啊?

    <bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" sc ...

随机推荐

  1. hdu5521 Meeting

    传送门 题目 Bessie and her friend Elsie decide to have a meeting. However, after Farmer John decorated hi ...

  2. Entity Framework Tutorial Basics(6):Model Browser

    Model Browser: We have created our first Entity Data Model for School database in the previous secti ...

  3. Entity Relationships

    Entity Relationships: Here, you will learn how entity framework manages the relationships between en ...

  4. kaggle Pipelines

    # Most scikit-learn objects are either transformers or models. # Transformers are for pre-processing ...

  5. 【C#】记录程序耗时方法

    最近写了一个读txt题库然后导入数据库的控制台应用,查看存入数据库耗时 在C#中使用 Stopwatch  命名空间: System.Diagnostics: 使用方法:   System.Diagn ...

  6. spring mvc常用注解标签

    @Controller 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model , ...

  7. InnoDB记录压缩及使用分析

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 这篇文章,源于RDS组内的一次饭后闲聊,两位小伙伴在探讨InnoDB启用压缩后的种种,比如在磁盘上是怎么存放 ...

  8. EasyUi取消选中表格的所有行

  9. LinkExtractor 构造器各参数说明

    LinkExtractor 构造器各参数说明 特例: LinkExtractor构造器的所有参数都有默认值 各参数说明: allow 接收一个正则表达式或一个正则表达式列表,提取绝对url与正则表达式 ...

  10. Linux系统磁盘

    所有有系统都一样,都是一种软件被安装于某个硬件之上,这个硬件无外非是一种存储设备,通常操作系统都是安装在磁盘中,所以Linux系统也是一样,都是安装在磁盘中,但是它与Windows系统不一样,因为Li ...