<!-- 排除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 Type Example Expression Description

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 {
...
}

最新文章

  1. SqlServer2008安装时提示重启计算机失败 解决办法
  2. 复旦大学2015--2016学年第一学期(15级)高等代数I期末考试第八大题解答
  3. SpringJMS解析2-JmsTemplate
  4. ECMAScript中关于如何获取this的定义
  5. Python 爬虫学习 urllib2
  6. iOS 获取文件的目录路径的几种方法 [转]
  7. SQL语句汇总(终篇)—— 表联接与联接查询
  8. 关于解决方案和web文件夹放在同一目录路径错误的问题
  9. 026 hibernate操作树形结构
  10. dotnet core如何编译exe
  11. ruby中to_s和to_str、to_i和to_int、to_a和to_ary、to_h和to_hash的解释说明
  12. 20175204 张湲祯 2018-2019-2《Java程序设计》第四周学习总结
  13. CUDA相关问题
  14. 小程序longpress的bug及其解决
  15. js实现oss文件上传及一些问题
  16. leetcode — substring-with-concatenation-of-all-words
  17. leetcode231
  18. 结对作业(1.0版)(bug1已修复)
  19. Django和Ajax
  20. C# 学习笔记(一) Winform利用Assembly反射动态创建窗体

热门文章

  1. centos7上安装zabbix4.0
  2. Opencv-Python学习笔记(一)
  3. CentOS7+CDH5.14.0安装全流程记录,图文详解全程实测-2设置SSH免密登录
  4. Python2和3版本对str和bytes类型的处理
  5. 监控服务器配置(一)-----Prometheus安装配置
  6. 爬坑记-tomcat 项目启动两次的的解决
  7. docker镜像运行错误排查
  8. laravel-更换语言包
  9. OO前三次作业分析
  10. Linux学习笔记:Jenkins的使用(二)