15、生命周期-BeanPostProcessor-后置处理器
2024-09-04 09:25:17
15、生命周期-BeanPostProcessor-后置处理器
- BeanPostProcessor 接口
package org.springframework.beans.factory.config;
import org.springframework.beans.BeansException;
import org.springframework.lang.Nullable;
public interface BeanPostProcessor {
// 初始化之前
@Nullable
default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
// 初始化之后
@Nullable
default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
}
15.1 编写MyBeanPostProcessor 实现BeanPostProcessor接口
package com.hw.springannotation.beans;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;
/**
* @Description 后置处理器
* @Author Administrator
* @Date 2018/11/28
*/
@Component // 将后置处理器加入到IOC容器中
public class MyBeanPostProcessor implements BeanPostProcessor {
/**
* @return 返回之后要用 的 bean
*/
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
System.out.println(" postProcessBeforeInitialization" + beanName + "> " + bean);
return bean;
}
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
System.out.println(" postProcessAfterInitialization" + beanName + "> " + bean);
return bean;
}
}
15.2 测试
最新文章
- XCode8向ITunes提交版本,不显示或提示无效的版本
- phpcms从表v9_news_data中字段content中用正则取出图片的地址输出
- Jeff Dean
- 分享一个刷网页PV的python小脚本
- css 集锦。
- 【Winform】DataTable绑定到ComboBox
- Aa3.0 事件机制
- APNS IOS 消息推送沙盒模式和发布模式
- Python+reuqests自动化接口测试
- 转载,matla滤波函数
- 利用sqlalchemy读取数据库 和pandas的Dataframe对象 互相生成
- Luffy之登录认证以及JWT
- 解决Win10家庭版没有‘本地用户和组’问题
- Driving proportional valves from microcontroller
- Safari不兼容Javascript中的Date问题
- BackBone.js之Router
- JavaScript 简介--对javascript的初识,最基础的了解
- VC 系统托盘编程,含有气泡提示
- CentOS6中OpenMP的运行时间或运行性能分析
- 在python中配置MySQL数据库