【sprinb-boot】@ComponentScan 跳过扫描 excludeFilters
@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class, RestController.class}))
前言
- springboot 2.0.0.RELEASE
- maven 3.5.0
自动扫描
默认扫描 @SpringBootApplication 类所在目录及子目录。
跳过扫描
@ComponentScan 搭配 excludeFilters
示例:
@ComponentScan(excludeFilters = @Filter(FilterType.ANNOTATION, classes = Controller.class))
- 1
参考:https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/api/index.html?org/springframework/boot/context/TypeExcludeFilter.html
FilterType
public enum FilterType {
/**
* Filter candidates marked with a given annotation.
* @see org.springframework.core.type.filter.AnnotationTypeFilter
*/
ANNOTATION,
/**
* Filter candidates assignable to a given type.
* @see org.springframework.core.type.filter.AssignableTypeFilter
*/
ASSIGNABLE_TYPE,
/**
* Filter candidates matching a given AspectJ type pattern expression.
* @see org.springframework.core.type.filter.AspectJTypeFilter
*/
ASPECTJ,
/**
* Filter candidates matching a given regex pattern.
* @see org.springframework.core.type.filter.RegexPatternTypeFilter
*/
REGEX,
/** Filter candidates using a given custom
* {@link org.springframework.core.type.filter.TypeFilter} implementation.
*/
CUSTOM
}
FilterType.ANNOTATION 按注解类型排除
@SpringBootApplication
@ComponentScan(excludeFilters = @Filter(FilterType.ANNOTATION, classes = Controller.class))
public class Application {
public static void main(String[] args) throws IOException {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("startup done.");
};
}
}
FilterType.REGEX 正则表示达
@SpringBootApplication
@ComponentScan(excludeFilters = @Filter(type = FilterType.REGEX, pattern = {"net.sayyy.db.*"}))
public class Application {
public static void main(String[] args) throws IOException {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("startup done.");
};
}
}
FilterType.CUSTOM 自定义规则
@SpringBootApplication
@ComponentScan(excludeFilters = @Filter(type = FilterType.CUSTOM, classes = MyCustomerFilter.class))
public class Application {
public static void main(String[] args) throws IOException {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("startup done.");
};
}
}
自定义过滤规则是需要实现 TypeFilter 接口
自定义扫描规则, 匹配类名中带有 Service 的类
public class MyCustomerFilter implements TypeFilter {
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
String className = metadataReader.getClassMetadata().getClassName();
return className.contains("Service");
}
}
【sprinb-boot】@ComponentScan 跳过扫描 excludeFilters的更多相关文章
- SpringMVC 源码深度解析<context:component-scan>(扫描和注冊的注解Bean)
我们在SpringMVC开发项目中,有的用注解和XML配置Bean,这两种都各有自己的优势,数据源配置比較经经常使用XML配置.控制层依赖的service比較经经常使用注解等(在部署时比較不会改变的) ...
- spring boot controller路由 url 扫描不到问题
spring boot项目出现controller的路由没被注册,原因:启动类application跟controller不在一个包中,扫描不到controller, 如启动类在com.oyx.a,c ...
- context:component-scan 注解的扫描
<context:component-scan base-package="com.matt.cloud"/> bean-context中 spring.handler ...
- Spring Boot项目跳转不到jsp页面是怎么回事
SpringBoot访问不了JSP但却能进入后台 一直报错: 解决方法: 改成下面的
- 【Spring源码分析系列】启动component-scan类扫描加载过程
原文地址:http://blog.csdn.net/xieyuooo/article/details/9089441/ 在spring 3.0以上大家都一般会配置一个Servelet,如下所示: &l ...
- spring启动component-scan类扫描加载过程(转)
文章转自 http://www.it165.net/pro/html/201406/15205.html 有朋友最近问到了 spring 加载类的过程,尤其是基于 annotation 注解的加载过程 ...
- 精尽Spring Boot源码分析 - 剖析 @SpringBootApplication 注解
该系列文章是笔者在学习 Spring Boot 过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring Boot 源码分析 GitHub 地址 进行阅读 Sprin ...
- 【springboot】给你一份Spring Boot知识清单
目录: 一.抛砖引玉:探索Spring IoC容器 1.1.Spring IoC容器 1.2.Spring容器扩展机制 二.夯实基础:JavaConfig与常见Annotation 2.1.JavaC ...
- Spring Boot 自动扫描组件
使用@ComponentScan自动扫描组件 案例准备 1.创建一个配置类,在配置类上添加 @ComponentScan 注解.该注解默认会扫描该类所在的包下所有的配置类,相当于之前的 <con ...
- spring boot(二):启动原理解析
我们开发任何一个Spring Boot项目,都会用到如下的启动类 @SpringBootApplication public class Application { public static voi ...
随机推荐
- 2024年8月中国数据库排行榜:OceanBase攀升再夺冠,达梦跃入三甲关
在这个炽热的季节,随着巴黎奥运会的盛大开幕,全球将目光聚集在了体育的无限魅力和竞技的巅峰对决上.如同奥运赛场上的激烈角逐,中国数据库界也上演着一场技术与创新的较量,各个数据库产品正在中国乃至全球舞台上 ...
- iOS中MJExtension使用详解
iOS开发中MVC模式最为常见,M代表模型,字典转成模型数据可以简化很多操作,下面我们说一下具体用法. 1.将字典转换成模型对象,模型中的属性名和responseObject字典中的字段名一致,我们得 ...
- 将数组数据转化成树形结构 tranListToTreeData
export function tranListToTreeData(list, rootValue) { // list是最完整的数组 let arr = []; // 记录儿子 list.forE ...
- 38. data为什么是一个函数
vue中的data为什么是返回对象的函数,而不是直接使用对象形式 : 我们复用组件的时候,要求每一份data数据之间是独立的,不能互相影响,如果写成对象的形式所有的组件使用一份data数据 ,如果使用 ...
- Vmware挂载san存储_vSphere 6.x 共享存储LUN丢失分区表修复(精华)
Vmware挂载san存储_vSphere 6.x 共享存储LUN丢失分区表修复 炎炎夏夜客户机房空调意外故障,前端ESXI物理服务器由于温度过高都自保关机,存储和SAN没有自保关机.上班修复空调后, ...
- KubeSphere 镜像构建器(S2I)服务证书过期解决方案
目前 KubeSphere 所有 3.x.x 版本,如果开启了 DevOps 模块并使用了镜像构建器功能(S2I)都会遇到证书过期问题. 解决方法 已开启 DevOps 模块 下载这个更新 S2I 服 ...
- 抽象队列同步器AQS
AQS是AbstractQueuedSynchronizer的简称,即抽象队列同步器,从字面上可以这样理解: 抽象:抽象类,只实现一些主要逻辑,有些方法由子类实现: 队列:使用先进先出(FIFO)的队 ...
- mysql替换内容
UPDATE storage SET guige = REPLACE(guige, '×', 'x')
- 部署包含Oracle数据源的项目
这段时间在处理公司EAS的数据报表,需要通过ETL进行数据的抽取,当ETL都完成并在本地跑成功后,总以为万事大吉了,没想到部署到作业后,却一直无法成功,百度搜索了好多方法,跟着上面去操作还是一直报错, ...
- 本地文件包含漏洞详解与CTF实战
1. 本地文件包含简介 1.1 本地文件包含定义 本地文件包含是一种Web应用程序漏洞,攻击者通过操控文件路径参数,使得服务器端包含了非预期的文件,从而可能导致敏感信息泄露. 常见的攻击方式包括: 包 ...