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