spring排除指定的类或者包扫描
<!-- 排除Controller注解的扫描 -->
<context:component-scan base-package="exampleBean">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<!-- 排除扫描符合正则表达式的类,此处排除com.wxm.util包下的所有类 -->
<context:component-scan base-package="exampleBean">
<context:exclude-filter type="regex"
expression="com.wxm.util.*"/>
</context:component-scan>
<!-- 排除指定包exampleBean下的CommFF类的扫描 -->
<context:component-scan base-package="exampleBean">
<context:exclude-filter type="assignable"
expression="exampleBean.CommFF"/>
</context:component-scan>
7.10.4 Using filters to customize scanning
By default, classes annotated with @Component, @Repository, @Service, @Controller, or a custom annotation that itself is annotated
with @Component are the only detected candidate components. However, you can modify and extend this behavior simply by applying custom filters. Add them as includeFilters or excludeFilters parameters of the @ComponentScan annotation (or as include-filter or exclude-filter sub-elements of the component-scan element). Each filter element requires the type and expression attributes. The following table describes the filtering options.
Filter Type Example Expression Description
annotation (ample.SomeAnnotation An annotation to be present at the type level in target components.
ample.SomeClass    A class (or interface) that the target components are assignable to (extend/implement). ample..*Service+An AspectJ type expression to be matched by the target components.
regex org\.example\.Default.*  A regex expression to be matched by the target components class names.
ample.MyTypeFilter    A custom implementation of the ype .TypeFilter interface.
The following example shows the configuration ignoring all @Repository annotations and using "stub" repositories instead.
spring怎么读取jar文件
@Configuration
@ComponentScan(basePackages = "ample",
includeFilters = @Filter(type = FilterType.REGEX, pattern = ".*Stub.*Repository"),
excludeFilters = @Filter(Repository.class))
public class AppConfig {
...
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。