spring和springboot相关总结(tmp)

spring和springboot相关总结(tmp)

spring容器中注册bean的方式

1.xml bean

2.@Component
3.@Configuration+@Bean
4.@Import直接引入
5.@Import + ImportSelector
6.@Import+ DeffedImportSelector
7.@Import + ImportBeanDefinitionRegistrar
8.FacytoryBean --> getObject 方法
9.BeanDefinitonRegisterPostProcessor

spring生命周期方法扩展点

初始化相关方法
@PostConstrut
InitLazingBean —> afterPropertiesSet() 方法
@Bean(initMethod=“xxxMethod”) 指定容器初始化方法

销毁方法
@PreDestroy
DisposableBean —> destroy() 方法
@Bean(destroyMethod=“xxxMethod”) 指定容器销毁方法

springboot启动执行方法

1.实现 ApplicationRunner 的 run 方法
2.CommandLineRunner 的 run 方法
3.@PostConstruct
4.InlizingBean 的 afterPropertiesSet() 方法
5.@Compoent 类 static 代码块

spring上下文ApplicationContext创建的几种方式

new ClassPathXmlApplicationContext(“applicationContext.xml”)

new XmlBeanFactory(new ClassPathResource(“applicationContext.xml”));

new AnnotationConfigApplicationContext(MainConfig.class)

@Configuration

@ComponentScan(“com.xxx”)

public class MainConfig{

}

new AnnotationConfigApplicationContext(“com.xxx”) 扫描包

BeanFactoryPostProcessor的扩展点

BeanFactoryPostProcssor扩展

@FunctionalInterface
public interface BeanFactoryPostProcessor {
    void postProcessBeanFactory(ConfigurableListableBeanFactory var1) throws BeansException;
}

BeanDefinitionRegistryPostProcessor

public interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor {
    void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry var1) throws BeansException;
}

说明:

BeanDefintionRegistryPostProcessor 也实现了

postProcessorBeanFactory(…) 方法

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值