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(…) 方法