spring扩展点(一、Spring Bean扩展接口)

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 {

    }
}

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值