Spring IOC容器中添加bean的集中方式(注解)
本文主要是介绍在使用spring 注解驱动开发的过程中像IOC容器中添加bean的几种方式,以及使用场景
1. 通过包扫描(ComponentScan)+(@Component/@Controller…)
这种方式是我们日常开发中最常用到的 spring将扫描路径下带有@Component/@Controller/@Service/@Repository注解的类添加到spring IOC容器中
ComponentScan 常用属性
- basePackages 指定包路径
在指定路径下的带有 @component/@Controller… 注解的类都会被加载进ioc 容器
- includeFilters 包含规则
Filter注解 用 FilterType.CUSTOM 可以自定义扫描规则 需要实现TypeFilter接口实现match方法 其中参数 MetadataReader 当前类的信息(注解,类路径,类原信息…) MetadataReaderFactory MetadataReader的工厂类
- excludeFilters 移除规则
同包含规则
包扫描注解使用
1万+


&spm=1001.2101.3001.11974&articleId=103402113&d=1&t=3&u=25f35475cc4147acb83610d892f8fb62)

被折叠的 条评论
为什么被折叠?



