1、InitialingBean
import org.springframework.beans.factory.InitializingBean;
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
**/
public class AAA implements InitializingBean {
@Override
public void afterPropertiesSet() throws Exception {
//顾名思义属性设置完成后执行这个方法
}
}
2、DisposableBean
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
**/
public class AAA implements DisposableBean {
@Override
public void destroy() throws Exception {
//顾名思义销毁时执行
}
}
3、BeanNameAware
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
**/
public class AAA implements BeanNameAware {
@Override
public void setBeanName(String s) {
//顾名思意设置beanName
}
}
4、ApplicationContextAware
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
**/
public class AAA implements ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//这里能拿到一个spring的容器上下文
}
}
5、BeanFactoryAware
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
**/
public class AAA implements BeanFactoryAware {
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
//让AAA具有BeanFactory的能力,这里能拿到beanFactory
}
}
6、FactoryBean
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
* 在对实例进行一些流程定制
**/
public class AAA implements FactoryBean {
@Override
public Object getObject() throws Exception {
return null;
}
@Override
public Class<?> getObjectType() {
return null;
}
@Override
public boolean isSingleton() {
return false;
}
}
7、BeanPostProcessor
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
**/
public class AAA implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
//bean初始化的前的操作
return null;
}
@Override
public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
//bean初始化的后的操作
return null;
}
}
8、BeanFactoryPostProcessor
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
**/
public class AAA implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
//bean初始化前,针对整个Bean的工厂中的bean进行配置
}
}
9、InstantiationAwareBeanPostProcessor
/**
* @Auth yaozhongjie
* @Date 2019/7/3 11:55
* bean实例化前后的处理
**/
public class AAA implements InstantiationAwareBeanPostProcessor {
@Override
public Object postProcessBeforeInstantiation(Class<?> aClass, String s) throws BeansException {
return null;
}
@Override
public boolean postProcessAfterInstantiation(Object o, String s) throws BeansException {
return false;
}
@Override
public PropertyValues postProcessPropertyValues(PropertyValues propertyValues, PropertyDescriptor[] propertyDescriptors, Object o, String s) throws BeansException {
return null;
}
@Override
public Object postProcessBeforeInitialization(Object o, String s) throws BeansException {
return null;
}
@Override
public Object postProcessAfterInitialization(Object o, String s) throws BeansException {
return null;
}
}
10、BeanDefinitionRegistryPostProcessor 接口继承了8、BeanFactoryPostProcessor接口
/**
* @Auth yaozhongjie
* @Date 2019/7/3 15:12
**/
public class AAA implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
}
}