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这两 ...
随机推荐
- 坑 flutter Positioned相关
child: new Positioned( right: 0.0, ...... 报错: Positioned widgets must be placed directly inside Stac ...
- java实现单例模式
1.饿汉模式 public class Singleton{ private static Singleton instance = new Singleton(); private Singleto ...
- WPF中的数据绑定(初级)
关于WPF中的数据绑定,初步探讨 数据绑定属于WPF中比较核心的范畴,以下是对WPF中数据绑定的一个初步探讨.个人感觉还是带有问题性质的叙述比较高效,也比较容易懂 第一,什么是数据绑定? 假定有这么一 ...
- select 的选中问题
function bind(pageIndex) { if (getQueryString("_status") == "3") {//从首页中慢病管理人数进入 ...
- 使用Tenorshare iCareFone for mac为iPhone做系统修复
tenorshare icarefonemac中文版采用一键式方法来保护,修理,清洁,优化并最终加快您的iPhone,iPad和iPod的速度.它可以帮助您轻松解决所有iOS问题,并让您的iPhone ...
- 20165213 Exp5 MSF基础应用
Exp5 MSF基础应用 实践内容 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 1.1一个主动攻击实践,如ms08_067; (1分) 1.2 一 ...
- SHELL脚本学习-练习写一个脚本4
#编写一个脚本时,自动生成”#!/bin/bash”这一行和相关注释信息. 把以下的代码保存为一个sh文件,比如test.sh , 新建脚本是使用 bash test.sh newfile 即可. ...
- OPENCV中特征提取和匹配的步骤
1.定义特征提取器和描述子提取器: cv::Ptr<cv::FeatureDetector> detector; cv::Ptr<cv::DescriptorExtractor> ...
- SCUCTF2018web部分wp
[签到] Web部分的签到题,打开连接后F12审查元素 可以看到有被隐藏起来的JSFuck密码,解码运行后可得flag [计算器] 打开后界面如上图,要求简单来说就是回答20道数学题目,每道题最多3s ...
- session实现原理(阿里面试题)
问: 当用户登录某网站后,向服务器发送一个请求,服务器如何判断是这个用户请求的 首先,你要明白一点,最初http协议在设计的时候,主要面向当时的web1.0网站,他们不需要知道是谁来访问,只需要向外界 ...