spring 排除指定的类或者包扫描
<!-- 排除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) |
|
An annotation to be present at the type level in target components. |
|
assignable |
|
A class (or interface) that the target components are assignable to (extend/implement). |
|
aspectj |
|
An AspectJ type expression to be matched by the target components. |
|
regex |
|
A regex expression to be matched by the target components class names. |
|
custom |
|
A custom implementation of the |
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 排除指定的类或者包扫描的更多相关文章
- Spring和Spring MVC包扫描
在Spring整体框架的核心概念中,容器是核心思想,就是用来管理Bean的整个生命周期的,而在一个项目中,容器不一定只有一个,Spring中可以包括多个容器,而且容器有上下层关系,目前最常见的一种场景 ...
- Spring IoC 源码分析 (基于注解) 之 包扫描
在上篇文章Spring IoC 源码分析 (基于注解) 一我们分析到,我们通过AnnotationConfigApplicationContext类传入一个包路径启动Spring之后,会首先初始化包扫 ...
- 不会吧,有人用了两年Spring, 居然不知道包扫描是怎么实现的
全栈的自我修养: 0004 Java 包扫描实现和应用(File篇) I may not be able to change the past, but I can learn from it. 我也 ...
- 全栈的自我修养: 0005 Java 包扫描实现和应用(Jar篇)
全栈的自我修养: 0005 Java 包扫描实现和应用(Jar篇) It's not the altitude, it's the attitude. 决定一切的不是高度而是态度. Table of ...
- Spring源码分析-从@ComponentScan注解配置包扫描路径到IoC容器中的BeanDefinition,经历了什么(一)?
阅前提醒 全文较长,建议沉下心来慢慢阅读,最好是打开Idea,点开Spring源码,跟着下文一步一步阅读,更加便于理解.由于笔者水平优先,编写时间仓促,文中难免会出现一些错误或者不准确的地方,恳请各位 ...
- Spring 自动转配类 在类中使用@Bean 注解进行转配但是需要排除该类说明
在spring中可以使用 @Component @Configuration @Bean(实例化后返回该bean)进行类实例的自动装配. 需求: 排除指定需要自动转配的类. 说明: 1.在以上注解中 ...
- 为啥Spring和Spring MVC包扫描要分开
开始学习springmvc各种小白问题 根据例子配置了spring扫描包,但是一直提示404错误,经过大量搜索,发现,扫描包的配置应该写在springmvc的配置文件中,而不是springmvc 配置 ...
- 整合Spring时Service层为什么不做全局包扫描详解
合Spring时Service层为什么不做全局包扫描详解 一.Spring和SpringMVC的父子容器关系 1.讲问题之前要先明白一个关系 一般来说,我们在整合Spring和SpringMVC这两个 ...
- spring盒springMVC整合父子容器问题:整合Spring时Service层为什么不做全局包扫描详解
整合Spring时Service层为什么不做全局包扫描详解 一.Spring和SpringMVC的父子容器关系 1.讲问题之前要先明白一个关系 一般来说,我们在整合Spring和SpringMVC这两 ...
随机推荐
- Ubuntu 通过apt安装VSCode
1. sudo vim /etc/apt/sources.list.d/vscode.list 并向里面添加:deb [arch=amd64] http://packages.microsoft.co ...
- 【搬运】 Page Object 官方文档 (新增了Widget特性)
Appium Java client has facilities which components to [Page Object](https://github.com/SeleniumHQ/se ...
- 从零开始学spring cloud(九) -------- 超时机制,断路器模式介绍
目前存在的问题: 现在我们假设一下,服务提供者响应非常缓慢,那么消费者对提供者的请求就会被强制等待,直到服务返回.在高负载场景下,如果不做任何处理,这种问题很可能造成所有处理用户请求的线程都被耗竭,而 ...
- 从零开始学spring cloud(七) -------- Spring Cloud OpenFegin
一.OpenFegin 介绍 Feign是一个声明性的Web服务客户端. 它使编写Web服务客户端变得更容易. 要使用Feign,请创建一个界面并对其进行注释. 它具有可插入的注释支持,包括Feign ...
- java基础 -- 经典排序
---- 冒泡排序 方法: 1.每次比较相邻的两个数 2. 小的交换在前面 3.每轮结束后最大的数交换到最后 代码实现: /* * 冒泡排序 * */ public class SortNum { ...
- git log命令常用参数集合
git log 查看 提交历史 默认不用任何参数的话,git log 会按提交时间列出所有的更新,最近的更新排在最上面. 常用的格式占位符写法及其代表的意义.选项 说明%H 提交对象(commit)的 ...
- 避免切换横竖屏Fragment的重复加载导致UI混乱
当我们切换横竖屏时 Activity的生命周期就会重走一遍,自然 其中的Fragment的生命周期也就重新走了一遍,实践证明 当熄屏 再开屏时 Fragment的生命周期也会重走一遍 解决方案: an ...
- VBA解析Json(转)
Sub bluejson() 'ok Dim aa Set x = CreateObject("ScriptControl"): x.Language = "JScrip ...
- sourcetree 跳过首次登录
定位到用户缓存数据目录:(需要在文件夹选项中 开启不隐藏文件夹和不隐藏文件扩展名) 一般为: C:\Users\{用户名}\AppData\Local\Atlassian 进入sourcetree目录 ...
- 浏览器中的 JS 和 Node.js 中的 JS
一个是前端技术,一个是后端技术 浏览器中的 JavaScript ECMAScript 语言基础,如语法.数据类型结构.一些内置对象 BOM(Browser Object Model) 一些操作页 ...