給容器注冊(cè)組件常用方式:
一.包掃描+注解標(biāo)注(@Controller/@Service/@Repository/@Component..)
二.@Configuration +@Bean 導(dǎo)入第三方包中的組件
三.@Import 快速給容器導(dǎo)入組件:
?1.@Import(XXX.class): 返回Bean的Id為全類名
;
?2.實(shí)現(xiàn)ImportSelector: 返回需要導(dǎo)入組件的全類名數(shù)組
;
?3.實(shí)現(xiàn)ImportBeanDefinitionRegistrar:手動(dòng)注冊(cè)Bean到容器中
;
四.實(shí)現(xiàn)FactoryBean<T>
五.InitializingBean/DisposableBean,@PreDestroy/@PostConstruct,@Bean(initMethod = "init", destroyMethod = "destroy"), BeanPostProcessor
image.png