文章字数:216,阅读全文大约需要1分钟
将普通类导入到
IOC容器中的注解
导入Bean的方法有
@Bean注解@Controller@Service@Repository@Component等注解类,使用@ComponentScan扫描包@Import方法注入(4.2之前只能导入配置类)
常用方式
- 在
@Enablexxx注解中使用,此注解声明的类在加载之前会加载@inport注解中的类 - 配合
ImportSelector.class接口使用
1 | // BeanFactoryAware可以获取beanFactory相关信息 |
1 | // 声明注解,并使用MyImportSelector |
1 | // 在配置类上使用注解,就能在加载配置类之前加载好选择的类 |