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这两 ...
随机推荐
- 词根:lun = moon, 表示“月亮”
词根:lun = moon, 表示“月亮” lunar [lun月亮,-ar形容词后缀,…的] 月亮的,太阴的,似月的,新月形的 semilunar [semi-半,lun月亮,-ar形容词后缀,…的 ...
- @ManyToMany的学习
新建了一个manyToMany的学生-课程表,学生可以选择多个课程,多个课程可以被学生选.尝试如下代码,创建了两个list,然后新建对象,加入list,然后set<list>,报错,这是因 ...
- centos7 端口3306无法连接问题
MySQL建用户的时候会指定一个host,默认是127.0.0.1/localhost,那么这个用户就只能本机访问,其它机器用这个用户帐号访问会提示没有权限,host改为%,表示允许所有机器访问. G ...
- stark组件开发之组合搜索基本显示
数据的获取,上一篇,已经有了!然后就是,如何进行展示的问题.到了展示这里,又有了新的问题, 因为从数据库,取得的数据. 分为 queryset 和 tuple 两种数据结构.tuple 中,只是字符串 ...
- PHP整理--PHP面向对象
一.定义类 使用关键字class定义 二.实例化对象 使用关键字new实例化对象 三.类成员的添加和访问 (1)类成员:属性.方法.常量 (2)添加成员需要使用修饰符 public.protect ...
- 关于egg.js的安全延伸思考
我看到全部的安全基于围绕http来操作,那么如果我只用websocket传输数据,是不是就会好很多?
- oracle的部分增删查改
1. 创建表空间 create tablespace (demo)表名 logging datafile( 表空间存放的位置) ‘D:\app\Administrator\oradata\orcl\ ...
- linux 图形化界面 && 谷歌浏览器 安装
一.图形化界面安装 yum groupinstall "Desktop" 如果运行显示 则 yum groupinstall "X Window System" ...
- 最小化webpack项目
先把代码贴出来,以后慢慢加说明 参考资料:入门 Webpack,看这篇就够了 / webpack 搭建自动打开,刷新浏览器 一.功能代码1.index.html <!DOCTYPE html&g ...
- Python中的迭代器、生成器
from collections import Iterable, Iterator 1. 可迭代(iterable)对象 参考官网链接 class I: def __init__(self, v): ...