Inversion Of Control
IOC,控制反转。对象创建的权力转移到外部容器。
在实现类上加入注释@Component(@Controller@Service@Repository)。
DI,Dependency Injection,依赖注入。容器为程序提供资源。
在创建对象时,new替换为注释@Autowired。
注释@ComponentScan
包含在启动类注解@SpringBootApplication中,默认扫描启动类以及其子包的javabean。
解决多个component?
1.@Primary
2.@Qualifier
3.@Resource。与Autowired区别?前者JDK提供,后者Spring提供;前者按名称注入,后者按类型注入。