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 ...
随机推荐
- 条件编译用法(#ifndef #define #endif#else)
1. 文件中的#ifndef 头件的中的#ifndef,这是一个很关键的东西.比如你有两个C文件,这两个C文件都include了同一个头文件.而编译时,这两个C文件要一同编译成一个可运行文件,于是问题 ...
- Angular js总结
之前看过一些angular js的相关技术文档,今天在浏览技术论坛的时候发现有问angular js是做什么用的? 于是有了一个想法,对于自己对angular js 的认知做一个总结. 总结: ang ...
- jquery delegate
代码如下: $('#container').delegate('a','click',function(){alert('That tickles!')} JQuery扫描文档查找$('#cont ...
- Struts2 web.xml文件配置
在导入了项目需要使用的核心jar包之后需要在web.xml中配置Struts. 1. Struts2的知识点普及: Struts2共有5类配置文件,分别罗列如下: 1), Web.xml; 在没有使用 ...
- backbone案例
http://www.kuqin.com/webpagedesign/20120807/324101.html http://udonmai.com/code/todos-backbone%E6%A1 ...
- Windows Phone 8 开发环境搭建
原地址:http://blog.csdn.net/md521/article/details/11015139 Windows Phone 8将采用与Windows 8相同的NT内核,这就意味着WP8 ...
- Jmeter 执行java脚本结束时提示:he JVM should have exitted but did not
使用jmeter执行java协议测试结束时会提示:he JVM should have exitted but did not ,jmeter2.11以后的可以 通过设置: jmeteren ...
- NGUI 的使用教程与实例(入门)(1 )
NGUI教程:步骤1-Scene 1.创建一个新的场景(New Scene).2.选择并删除场景里的MainCamera.3.在NGUI菜单下选择Create a New UI,会打开UI创建向导. ...
- TYPE C PD测试板 UFP测试板
- SSH框架应用中常用Jar包用途介绍
struts2需要的几个jar包:1)xwork-core-2.1.62)struts2-core-2.1.83)ognl-2.7.34)freemarker-2.3.155)commons-io-1 ...