8 -- 深入使用Spring -- 1...4 重写占位符配置器
8.1.5 重写占位符配置器 (PropertyOverrideConfigurer)
PropertyOverrideConfigurer是Spring提供的另一个容器后处理器。PropertyOverrideConfigurer的属性文件指定的信息可以直接覆盖Spring配置文件中的元数据。
使用PropertyOverrideConfigurer的属性文件,每条属性应保持如下格式:beanId.property = value
beanId 是属性占位符试图覆盖的Bean的id,Property是试图覆盖的属性名(对应于调用setter方法)。
XML :
<?xml version="1.0" encoding="UTF-8"?>
<!-- Spring 配置文件的根元素,使用Spring-beans-4.0.xsd语义约束 -->
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
<property name="locations">
<list>
<value>dbconn.properties</value>
<!-- 如果有多个属性文件,依次在下面列出来 -->
<!-- <value>wawa.properties</value> -->
</list>
</property>
</bean> <!-- 对于采用基于XML Schema的配置文件而言,如果导入了context:命名空间,则可采用如下方式来配置该属性占位符 -->
<!-- <context:property-override location="classpath:wawa.properties"/> --> <!-- 定义数据源Bean,使用C3P0数据源实现 -->
<!-- 配置该Bean时没有指定任何信息,但Properties文件里的信息将会直接覆盖该Bean的属性值。 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
</bean> </beans>
Properties :
dataSource.jdbc.driverClassName=com.mysql.jdbc.Driver
dataSource.jdbc.url=jdbc:mysql://localhost:3306/spring
dataSource.jdbc.username=root
dataSource.jdbc.password=system
由于PropertyOverrideConfigurer容器后处理器,Spring容器使用ApplicationContext作为容器时,容器会自动检测容器后处理器,并使用该容器后处理器来处理Spring容器。
beanId必须是容器中真是存在的Bean的id,否则程序将出错。
如果有多个PropertyOverrideConfigurer对同一个Bean属性进行了覆盖,最后一次覆盖将会获胜。
啦啦啦
8 -- 深入使用Spring -- 1...4 重写占位符配置器的更多相关文章
- 8 -- 深入使用Spring -- 1...4 属性占位符配置器
8.1.4 属性占位符配置器 PropertyPlaceholderConfigurer 是一个容器后处理器,负责读取Properties属性文件里的属性值,并将这些属性值设置成Spring配置文件的 ...
- spring4笔记----PropertyOverrideConfigureer 重写占位符配置器(图)
- spring4笔记----PropertyPlaceholderConfigurer 属性占位符配置器
driverClassName=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/spring username=root password= ...
- spring占位符解析器---PropertyPlaceholderHelper
一.PropertyPlaceholderHelper 职责 扮演者占位符解析器的角色,专门用来负责解析路劲中or名字中的占位符的字符,并替换上具体的值 二.例子 public class Prope ...
- Spring源码解析之PropertyPlaceholderHelper(占位符解析器)
Spring源码解析之PropertyPlaceholderHelper(占位符解析器) https://blog.csdn.net/weixin_39471249/article/details/7 ...
- 【mybatis源码学习】mybtias基础组件-占位符解析器
一.占位符解析器源码 1.占位符解析器实现的目标 通过解析字符串中指定前后缀中的字符,并完成相应的功能. 在mybtias中的应用,主要是为了解析Mapper的xml中的sql语句#{}中的内容,识别 ...
- Spring - IoC(12): 属性占位符
使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...
- Spring import配置文件使用占位符
import使用占位符 连接池切换导入配置的代码: <import resource="classpath:META-INF/spring/spring-${db.connection ...
- Spring与Mybatis整合占位符无法解析问题
问题:写了一个新的dao接口,进行单元测试时提示: Initialization of bean failed; nested exception is org.springframework.bea ...
随机推荐
- label文字居中
height: height,//"20px" "line-height": height, autosize:true, &qu ...
- [kafka] 001_kafka起步
一.简介 Kafka is a distributed, partitioned, replicated commit log service. It provides the functionali ...
- 6 ways to import data into SQL Server
I’m going to go over some methods to import data from text files into SQL Server today. The particul ...
- 8个日志级别(OFF、FATAL、ERROR、WARN、INFO、DEBUG、TRACE、 ALL)
log4j定义了8个级别的log(除去OFF和ALL,可以说分为6个级别),优先级从高到低依次为:OFF.FATAL.ERROR.WARN.INFO.DEBUG.TRACE. ALL. ALL 最低等 ...
- github开源库(三)
41.android-swipelistview SwipeListView是一个Android List View实现,实现了自定义ListView单元格,可通过滑动来显示扩展面板.开发者可直接登陆 ...
- 关于Unity中的本地存储
本地存储 在做游戏的时候,经常需要在本机存储一些数据,比如闯关类游戏要记录闯到第几关,做单机的时候要把数据保存到本地,下次启动的时候数据存在,就是把数据保存到磁盘里面或者手机的flash闪存里面. U ...
- Solr系列三:solr索引详解(Schema介绍、字段定义详解、Schema API 介绍)
一.Schema介绍 1. Schema 是什么? Schema:模式,是集合/内核中字段的定义,让solr知道集合/内核包含哪些字段.字段的数据类型.字段该索引存储. 2. Schema 的定义方式 ...
- SpringMVC系列(二): SpringMVC各个注解的使用
1.@RequestMapping 1.@RequestMapping除了能修饰方法,还能修饰类(1)修饰类:提供初步的请求映射信息,相对于web请求的根目录(2)修饰方法:提供进一步的细分映射信息相 ...
- AngularJS $http模块POST数据,后台接受不到
1.问题: 后端接收不到AngularJs中$http.post发送的数据,总是显示为null 示例代码: $http.post(/admin/KeyValue/GetListByPage, { pa ...
- com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method
查看了网友们的错误原因, 需要进行实例化的类没有进行实例化,具体没有实例化的类会在错误信息中显示,在错误信息中搜索“Serializable”即可找到将其实现序列化可消除错误. 是在使用Dubbo提供 ...