<!-- 排除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 {
...
}

spring 排除指定的类或者包扫描的更多相关文章

  1. Spring和Spring MVC包扫描

    在Spring整体框架的核心概念中,容器是核心思想,就是用来管理Bean的整个生命周期的,而在一个项目中,容器不一定只有一个,Spring中可以包括多个容器,而且容器有上下层关系,目前最常见的一种场景 ...

  2. Spring IoC 源码分析 (基于注解) 之 包扫描

    在上篇文章Spring IoC 源码分析 (基于注解) 一我们分析到,我们通过AnnotationConfigApplicationContext类传入一个包路径启动Spring之后,会首先初始化包扫 ...

  3. 不会吧,有人用了两年Spring, 居然不知道包扫描是怎么实现的

    全栈的自我修养: 0004 Java 包扫描实现和应用(File篇) I may not be able to change the past, but I can learn from it. 我也 ...

  4. 全栈的自我修养: 0005 Java 包扫描实现和应用(Jar篇)

    全栈的自我修养: 0005 Java 包扫描实现和应用(Jar篇) It's not the altitude, it's the attitude. 决定一切的不是高度而是态度. Table of ...

  5. Spring源码分析-从@ComponentScan注解配置包扫描路径到IoC容器中的BeanDefinition,经历了什么(一)?

    阅前提醒 全文较长,建议沉下心来慢慢阅读,最好是打开Idea,点开Spring源码,跟着下文一步一步阅读,更加便于理解.由于笔者水平优先,编写时间仓促,文中难免会出现一些错误或者不准确的地方,恳请各位 ...

  6. Spring 自动转配类 在类中使用@Bean 注解进行转配但是需要排除该类说明

    在spring中可以使用 @Component @Configuration @Bean(实例化后返回该bean)进行类实例的自动装配. 需求: 排除指定需要自动转配的类. 说明: 1.在以上注解中  ...

  7. 为啥Spring和Spring MVC包扫描要分开

    开始学习springmvc各种小白问题 根据例子配置了spring扫描包,但是一直提示404错误,经过大量搜索,发现,扫描包的配置应该写在springmvc的配置文件中,而不是springmvc 配置 ...

  8. 整合Spring时Service层为什么不做全局包扫描详解

    合Spring时Service层为什么不做全局包扫描详解 一.Spring和SpringMVC的父子容器关系 1.讲问题之前要先明白一个关系 一般来说,我们在整合Spring和SpringMVC这两个 ...

  9. spring盒springMVC整合父子容器问题:整合Spring时Service层为什么不做全局包扫描详解

    整合Spring时Service层为什么不做全局包扫描详解 一.Spring和SpringMVC的父子容器关系 1.讲问题之前要先明白一个关系 一般来说,我们在整合Spring和SpringMVC这两 ...

随机推荐

  1. ACM学习之路

     2018-10-18 11:03:00 今天开始踏上实现梦想的道路,希望自己不要懈怠. 坚持做简单的事,坚持下来就会变得不简单.

  2. AD16PCB如何快速删除走线

    工具(Tools)取消布线(Un_Route)全部(AII) ad pcb画图,如果想整体去掉一条线,只要是连接在一起的,不管在哪一层,都可以采取如下方法:1.PCB画面下,按组合键Ctrl+H,会出 ...

  3. node 常用模块及方法fs,url,http,path

    http://www.cnblogs.com/mangoxin/p/5664615.html https://www.liaoxuefeng.com/wiki/001434446689867b2715 ...

  4. MyBatis updateByExample和updateByExampleSelective的区别

    大家都用过mybatis generator来生产数据库的xml文件,但是关于updateByExample和updateByExampleSelective的区别我之前一直分不太清楚. 如果分不清楚 ...

  5. go的语法

    概述 有接触go语言,工作中用的比较少,偶尔做个小项目,最近看到的一个项目也从go迁移到java. 但是对go还是恋恋不忘,它语法比较简洁,库也比较多,编译速度快,等等优点,让我忘不了. 对go的语法 ...

  6. SqlServer数据库链接字符串

    完整链接字符串: 1."DataSourse=.\你的实例;Initial Catalog=yourdatabase;User ID=*;Password=*;Trusted_Connect ...

  7. 关于Https

    http://blog.csdn.net/wfdtxz/article/details/8678982 https://www.tuicool.com/articles/feYfE3I https:/ ...

  8. Python之路(第三十三篇) 网络编程:socketserver深度解析

    一.socketserver 模块介绍 socketserver是标准库中的一个高级模块,用于网络客户端与服务器的实现.(version = "0.4") 在python2中写作S ...

  9. PHP去掉html中的空行、空白函数

    function DeleteHtml($str){ $str = trim($str); $str = ereg_replace("\t","",$str); ...

  10. AX_CreateAndPostInventJournal

    static void CreateAndPostInventJournal(Args _args) { InventJournalTable inventJournalTableLocal; Inv ...