惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Vercel News
Vercel News
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
N
Netflix TechBlog - Medium
Google DeepMind News
Google DeepMind News
H
Help Net Security
罗磊的独立博客
The Cloudflare Blog
J
Java Code Geeks
博客园 - 叶小钗
I
InfoQ
B
Blog
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
月光博客
月光博客
博客园_首页
雷峰网
雷峰网
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
美团技术团队
T
The Blog of Author Tim Ferriss
博客园 - 司徒正美

博客园 - chromecrown

MacBook M3 安卓系统层开发环境搭建 C# 语言规范 java web spring 发送邮件 spring-data-redis和jedis版本对应收集总结 python 多线程和多进程基本写法 python 调用nmap javascript定时函数 UML学习备忘 听王竑锜老师讲课笔记 WebLogic 8.1 部署问题记录 JavaScript中JSONObject和JSONArray相关知识备忘(网络转载) struts 2 result-types 备忘 小小菜鸟学习mysql 基本操作命令 备忘 VMware虚拟机网络配置相关备忘 visual Studio C# 环境下 创建windows 服务 使用C#调用系统API实现锁定计算机 心情状态---所困 jsf 阶段性总结
spring 排除指定的类或者包扫描
chromecrown · 2019-01-28 · via 博客园 - chromecrown
<!-- 排除Controller注解的扫描 -->
<context:component-scan base-package="exampleBean">
    <context:exclude-filter type="annotation"
        expression="org.springframework.stereotype.Controller" />
</context:component-scan>


<!-- 排除扫描符合正则表达式的类,此处排除com.wx.comm.util包下的所有类 -->
<context:component-scan base-package="exampleBean">
    <context:exclude-filter type="regex"
        expression="com.wx.comm.util.*" />
</context:component-scan>


<!-- 排除指定包exampleBean下的CommFF类的扫描 -->
<context:component-scan base-package="exampleBean">
    <context:exclude-filter type="assignable"
        expression="exampleBean.CommFF" />
</context:component-scan>

参考:https://docs.spring.io/spring/docs/4.3.12.RELEASE/spring-framework-reference/htmlsingle/

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 excludeFiltersparameters 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 TypeExample ExpressionDescription

annotation (default)

org.example.SomeAnnotation

An annotation to be present at the type level in target components.

assignable

org.example.SomeClass

A class (or interface) that the target components are assignable to (extend/implement).

aspectj

org.example..*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.

custom

org.example.MyTypeFilter

A custom implementation of the org.springframework.core.type .TypeFilter interface.

The following example shows the configuration ignoring all @Repository annotations and using "stub" repositories instead.

@Configuration
@ComponentScan(basePackages = "org.example",
        includeFilters = @Filter(type = FilterType.REGEX, pattern = ".*Stub.*Repository"),
        excludeFilters = @Filter(Repository.class))
public class AppConfig {
    ...
}