spring 框架说明文档学习记录(3.6)
来源:互联网 发布:乐视网络连接出现异常 编辑:程序博客网 时间:2024/06/06 09:40
容器扩展
一般的,应用开发者不需要继承实现ApplicationContext。与之相对的,Spring IOC容器能够通过引入特别集成接口来扩展。
使用BeanPostProcessor定制bean
我们可以通过实现BeanPostProcessor接口定义的回调函数来实现自己的实例化逻辑、依赖解决逻辑等等。如果你想在Spring容器完成实例化、配置或初始化bean后实现一些逻辑,你可以引入一个或多个BeanPostProcessor实现。
你可以配置多个BeanPostProcessor实例,并通过设置order属性来控制BeanPostProcessor的执行顺序。仅在BeanPostProcessor实现Ordered接口时才可设置该属性,如果你编写自己的BeanPostProcessor,你也应该考虑继承Ordered接口。
简单示例
package scripting;import org.springframework.beans.factory.config.BeanPostProcessor;import org.springframework.beans.BeansException;public class InstantiationTracingBeanPostProcessor implements BeanPostProcessor { // simply return the instantiated bean as-is public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; // we could potentially return any object reference here... } public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { System.out.println("Bean '" + beanName + "' created : " + bean.toString()); return bean; }}
<?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:lang="http://www.springframework.org/schema/lang" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd"> <lang:groovy id="messenger" script-source="classpath:org/springframework/scripting/groovy/Messenger.groovy"> <lang:property name="message" value="Fiona Apple Is Just So Dreamy."/> </lang:groovy> <!-- when the above bean (messenger) is instantiated, this custom BeanPostProcessor implementation will output the fact to the system console --> <bean class="scripting.InstantiationTracingBeanPostProcessor"/></beans>BeanFactoryPostProcessor
PropertyPlaceholderConfigurer
PropertyOverrideConfigurer
FactoryBean
阅读全文
0 0
- spring 框架说明文档学习记录(3.6)
- spring 框架说明文档学习记录(1)
- spring 框架说明文档学习记录(2)
- spring 框架说明文档学习记录(3)
- spring 框架说明文档学习记录(3.1)
- spring 框架说明文档学习记录(3.2)
- spring 框架说明文档学习记录(3.3)
- spring 框架说明文档学习记录(3.4)
- spring 框架说明文档学习记录(3.5)
- spring 框架说明文档学习记录(3.7)
- Spring框架学习记录
- Spring-Validator 说明文档
- Spring-Validator 说明文档
- Spring说明文档翻译1——第一部分,spring框架预览
- spring框架说明
- Spring Framework 5.0.0.M3中文文档 翻译记录 Part I. Spring框架概览1-2.2
- Spring的定时器说明文档
- Spring Framework 中文说明文档
- 编程第八十九天
- C#禁止重复运行程序,并激活原托盘程序
- 从物理执行的角度透视SparkJob
- 纳税服务系统【角色与用户】
- 计算机网络之数据链路层
- spring 框架说明文档学习记录(3.6)
- JQuery的父、子、兄弟节点查找方法
- 生成SSL证书的方法
- windows下的tensorflow安装
- 编程第九十天
- PHP笔记
- jquery 的ready,onload,unload用法和写法
- DOM、jQuery对象
- 转 PHP四舍五入精确小数位及取整