springboot自动装配介绍

所谓的自动装配,就是 autowire。

如何激活自动装配呢?

方法一:@EnableAutoConfiguration或@SpringBootApplication,写在@Configuration的类上。

方法二:对于xml的,采用ClassPathXmlApplicationContext加载

方法三:对于@Import、@ComponentScan,采用AnnotationConfigApplicationContext注册。

自动装配策略有那些?

byType(默认)

byName

constructor

 

@AutoWired

默认采用byType,如果该类型有多个实例,则尝试使用byName匹配,如果byName也确定不了,可通过@Primary和@Priority来确定。

 

你可能感兴趣的:(springboot自动装配介绍)