Spring(1)_IOc容器註冊組件方式
IOc容器註冊組件方式:
_1.包掃描+註解形式(@Component,@Service,@Controller,@Repository)
__1.@ComponentScan/@ComponentScans/@Filter
__2.@Scope&& @Lazy 作用域與懶加載
__3.@Conditional(Class<? implements Condition>) 註冊條件過濾
_2.通過@Bean的方式[導入第三方包裏面的組件]
_3.通過@Import的方式
__1.@Import(Class<?>):容器會自動裝載這個組件,id默認爲全類名
__2.@Import(Class<? implements ImportSelector>):返回需要導入的全類名數組
__3.@Import(Class<? implements ImportBeanDefinitionRegistrar>):手動註冊bean到容器中
_4.通過FactoryBean接口的方式(工廠Bean)
__1.默認獲取的是工廠Bean調用getObject創建對象
__2.獲取工廠Bean本身,我們需要給id的前面加上&,&colorFactoryBean