XI.spring的点点滴滴--IObjectFactoryPostProcessor(工厂后处理器)
承接上文
IObjectFactoryPostProcessor(工厂后处理器))
前提是实现接口的对象注册给当前容器
- 直接继承的对象调用这个postProcessBeanFactory方法,参数为工厂
- 添加对象配置在xml中用IApplicationContext自动注册
接口名称分别为.net的Spring.Objects.Factory.Config.IObjectFactoryPostProcessor
与Java的org.springframework.beans.factory.config.BeanFactoryPostProcessorpostProcessBeanFactory就一个方法,参数为创建工厂的对象,
方法的作用就是可以在对象定义被载入容器之后并且在被实例化之前执行某些行为spring提供的实现类(两个接口的实现类唯一的不同点是一个
是用占位符一个是直接用实例后对象的属性名)- PropertyPlaceholderConfigurer,其中基本用法如下,默认当变量不存在对应的值的时候会获取系统的环境变量
C#:这个类的参数是键值对存在的,configSections属性设置了那个节点为要获取的键值对,
EnvironmentVariableMode为枚举,有三个可用值:Never、Fallback和Override。
其中Fallback是默认值,会尝试用环境变量替换未在自定义键值对中找到匹配项的占位符
;Override则不理会自定义键值对中是否有与占位符匹配的键,直接用环境变量值替换占位符;
Nerver即不使用环境变量进行替换<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context"
type="Spring.Context.Support.ContextHandler, Spring.Core"/>
</sectionGroup>
<section name="DaoConfiguration"
type="System.Configuration.NameValueSectionHandler"/>
<section name="DatabaseConfiguration"
type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<DaoConfiguration>
<add key="maxResults" value="1000"/>
</DaoConfiguration>
<DatabaseConfiguration>
<add key="connection.string"
value="dsn=MyDSN;uid=sa;pwd=myPassword;"/>
</DatabaseConfiguration>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects>
<object type="SpringBase.test,SpringBase">
<property name="result" value="${maxResults}"/>
<property name="connectionstring" value="${connection.string}"/>
</object>
<object
type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer,
Spring.Core">
<property name="configSections">
<value>DaoConfiguration,DatabaseConfiguration</value>
</property>
</object>
</objects>
</spring>
</configuration>java:其中classpath前缀表示在类文件地址开始,
searchSystemEnvironment设置是否搜索系统环境变量为布尔类型<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>
<bean class="springdemo.test" singleton="false">
<property name="name" value="${jdbc}" />
<property name="url" value="${jdbc.url}" />
</bean>config.properties
jdbc=aaa
jdbc.url=aaa - PropertyOverrideConfigurer(和前面的区别替换的依据不是占位符,而是属性名)
C#:其中的key为对象的属性名
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context"
type="Spring.Context.Support.ContextHandler, Spring.Core"/>
</sectionGroup>
<section name="DaoConfigurationOverride"
type="System.Configuration.NameValueSectionHandler"/>
</configSections>
<DaoConfigurationOverride>
<add key="test.result" value="1000"/>
</DaoConfigurationOverride>
<spring>
<context>
<resource uri="config://spring/objects"/>
</context>
<objects>
<object id="test" type="SpringBase.test,SpringBase">
<property name="result" value="11"/>
</object>
<object
type="Spring.Objects.Factory.Config.PropertyOverrideConfigurer,
Spring.Core">
<property name="configSections">
<value>DaoConfigurationOverride</value>
</property>
</object>
</objects>
</spring>
</configuration>java:
<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>
<bean id="jdbc" class="springdemo.test" singleton="false">
<property name="url" value="123" />
</bean>config.properties
jdbc.url=aaa
- PropertyPlaceholderConfigurer,其中基本用法如下,默认当变量不存在对应的值的时候会获取系统的环境变量
- 上一篇:Ⅹ.spring的点点滴滴--IObjectPostProcessor(对象后处理器)
- 本文链接地址:XI.spring的点点滴滴--IObjectFactoryPostProcessor(工厂后处理器)
XI.spring的点点滴滴--IObjectFactoryPostProcessor(工厂后处理器)的更多相关文章
- Ⅹ.spring的点点滴滴--IObjectPostProcessor(对象后处理器)
承接上文 IObjectPostProcessor(对象后处理器) 前提是实现接口的对象注册给当前容器 C#: 通过继承AbstractObjectFactory对象的AddObjectPostPro ...
- 品Spring:bean工厂后处理器的调用规则
上一篇文章介绍了对@Configuration类的处理逻辑,这些逻辑都写在ConfigurationClassPostProcessor类中. 这个类不仅是一个“bean工厂后处理器”,还是一个“be ...
- Ⅸ.spring的点点滴滴--IObjectFactory与IFactoryObject的杂谈
承接上文 ObjectFactory与IFactoryObject的杂谈 .net篇(环境为vs2012+Spring.Core.dll v1.31) public class parent { pu ...
- 品Spring:详细解说bean后处理器
一个小小的里程碑 首先感谢能看到本文的朋友,感谢你的一路陪伴. 如果每篇都认真看的话,会发现本系列以bean定义作为切入点,先是详细解说了什么是bean定义,接着又强调了bean定义为什么如此重要. ...
- spring的组件工厂后置处理器——BeanFactoryPostProcessor
作用和调用时机 spring有两种后置处理器: 1. 组件后置处理器——org.springframework.beans.factory.config.BeanPostProcessor: 2. 工 ...
- Spring源码之BeanFactoryPostProcessor(后置处理器)
Spring源码之BeanFactoryPostProcessor(后置处理器). 有点水平的Spring开发人员想必都知道BeanFactoryPostProcessor也就是常说的后置管理器,这是 ...
- Spring Bean后处理器以及容器后处理器【转】
Bean后处理器:即当spring容器实例化Bean实例之后进行的增强处理. 容器后处理器:对容器本身进行处理,并总是在容器实例化其他任何Bean之前读取配置文件的元数据并可能修改这些数据. 一.Be ...
- Spring - BeanPostProcessor接口(后处理器)讲解
概述: BeanPostProcessor接口是众多Spring提供给开发者的bean生命周期内自定义逻辑拓展接口中的一个,其他还有类似InitializingBean,DisposableBean, ...
- Spring框架——后处理器
Bean的后处理 Spring容器实例化Bean实例之后进行的增强处理,关于这里的描述之前有点错误,现在来纠正一下:这个过程有点像AOP,不过我们知道AOP是对方法而言的,而Bean后处理器是针对Ja ...
随机推荐
- Codeforces Round #329 div2
Problem_A(593A): 题意: 给n个单词, 每个单词由小写字母组成, 且长度<=1000. 组成一篇文章的要求是: 所有单词所用字母 <= 2 即最多只能有两个不同的字母. 求 ...
- C#变成数据导入Excel和导出Excel
excel 基础 •整个excel 表格叫工作表:workbook:工作表包含的叫页:sheet:行:row:单元格:cell. •excel 中的电话号码问题,看起来像数字的字符串以半角单引号开头就 ...
- explain 用法详解
explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. 使用方法,在select语句前加上explain就可以了: 如: expla ...
- [状压dp]HDU5045 Contest
题意: n和人做m道题, 每俩人做的题数不能相差一题以上.(也就是每n道题分别由n个人完成) 给n个人分别做m道题的概率, 求完成m题的最大期望 $1\le N \le 10$ 注意!!! fil ...
- easyui源码翻译1.32--LinkButton(按钮)
前言 使用$.fn.linkbutton.defaults重写默认值对象.下载该插件翻译源码 按钮组件使用超链接按钮创建.它使用一个普通的<a>标签进行展示.它可以同时显示一个图标和文本, ...
- Qt Add ons Modules(听说QtSystem有接口可以获取 imei号)
http://wiki.qt.io/Qt-Add-ons-Modules 听说QtSystem有接口可以获取 imei号.http://wiki.qt.io/Qt-Add-ons-Modules这儿下 ...
- 一个Redis实现的分布式锁
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.redis.conne ...
- 【转】HTML中A标签与click事件的前世今生
在动态网页中,常常需要在单击超链接时处理一些数据,而不是跳转一个网页.在这种情况下,通常有以下三种处理方式: 不设置<a>标签的href属性,只设置onclick属性.在这种处理方式下,通 ...
- 应付期间 Payables Periods
(N) AP > Accounting > Control payables periods Click [Period Status] column to Open.
- poi大数据导入解决方法
This one comes up quite a lot, but often the reason isn't what you might initially think. So, the fi ...