<context:component-scan base-package="com.zd">
<!-- 配置自己设定的过滤条件 regex包过滤 所有匹配下面的包路径里面的类全部被spring实例化 -->
<context:include-filter type="regex" expression=".*.common.*"/>
<context:include-filter type="regex" expression=".*.aop.*"/>
<!-- 配置自己设定的过滤条件 aspectj类名称过滤 所有继承和扩展自Base的类都被实例化 -->
<context:include-filter type="aspectj" expression="com.zd.epa.base.Base+"/>
</context:component-scan>
context:component-scan base-package:自动扫描的包
context:include-filter过滤器有五种type:
- assignable-指定扫描某个接口派生出来的类
- annotation-指定扫描使用某个注解的类
- aspectj-指定扫描AspectJ表达式相匹配的类
- custom-指定扫描自定义的实现了org.springframework.core.type.filter.TypeFilter接口的类
- regex-指定扫描符合正则表达式的类
本文详细介绍了 Spring 框架中如何通过配置 context:component-scan 来自动扫描特定包及其子包内的组件,并利用不同类型的过滤器来精确控制哪些类将被实例化为 Spring Bean。特别关注了 assignable、annotation、aspectj、custom 和 regex 五种过滤器类型的应用场景。
474

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



