springboot启动时过滤不需要注入的类
在springbootApplication启动类上加入注解
@ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = XX.class))
public @interface ComponentScan {
.....................
/**
* Specifies which types are not eligible for component scanning.
* @see #resourcePattern
*/
Filter[] excludeFilters() default {};
.........................
/**
* Declares the type filter to be used as an {@linkplain ComponentScan#includeFilters
* include filter} or {@linkplain ComponentScan#excludeFilters exclude filter}.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({})
@interface Filter {
/**
* The type of filter to use.
* <p>Default is {@link FilterType#ANNOTATION}.
* @see #classes
* @see #pattern
*/
FilterType type() default FilterType.ANNOTATION;
...........................
}
}
其中@ComponentScan 注解属性excludeFilters可以过滤多个类型的类的加载,其中有内部类,可以指定过滤的类型,上面是指定class文件进行过滤,也可以指定其他类型的
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
}
springboot启动时过滤不需要注入的类的更多相关文章
- SpringBoot启动时 提示没有主清单属性 MANIFEST
SpringBoot启动时 提示没有主清单属性 MANIFEST <?xml version="1.0" encoding="UTF-8"?> &l ...
- springBoot启动时让方法自动执行的几种实现方式
一.开篇名义 在springBoot中我们有时候需要让项目在启动时提前加载相应的数据或者执行某个方法,那么实现提前加载的方式有哪些呢?接下来我带领大家逐个解答 1.实现ServletContextAw ...
- 【问题解决:信息提示】SpringBoot启动时提示The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
问题描述 springboot程序在启动时提示信息 [2018-10-24 21:59:05.214] - 440 信息 [restartedMain] --- org.apache.catalina ...
- Spring boot采坑记--- 在启动时RequstMappingHandlerMapping无法找到部分contorller类文件的解决方案
最近有一个心得需求,需要在一个现有的springboot项目中增加一些新的功能,于是就在controller文件包下面创建新的包和类文件,但是后端开发完之后,本地测试发现前端访问报404错误,第一反应 ...
- (28)SpringBoot启动时的Banner设置【从零开始学Spring Boot】
对于使用过Spring Boot的开发者来说,程序启动的时候输出的由字符组成的Spring符号并不陌生.这个是Spring Boot为自己设计的Banner: 1. . ____ ...
- springboot启动时控制台不显示映射的URL
背景 今天,第一次使用 2.2.0 版本的springboot,在访问接口时发现访问不到,于是在控制台进行 URL 搜索,发现并相关没有内容 原因 springboot版本差异,切换回 2.0.5.R ...
- springboot启动时执行任务CommandLineRunner
# SpringBoot中CommandLineRunner的作用> 平常开发中有可能需要实现在项目启动后执行的功能,SpringBoot提供的一种简单的实现方案就是添加一个model并实现Co ...
- SpringBoot启动时的Banner设置
Spring Boot程序启动的时候输出的由字符组成的Spring符号并不陌生.这个是Spring Boot为自己设计的Banner: 1. 第一种方式:修改的时候,进行设置,在Application ...
- springboot 启动时执行方法
Springboot提供了两种“开机启动”某些方法的方式:ApplicationRunner和CommandLineRunner.下面简单介绍下ApplicationRunner 1.创建个Tests ...
随机推荐
- web.xml中配置——解决post乱码
<!-- 解决post乱码 --> <filter> <filter-name>CharacterEncodingFilter</filter-name> ...
- idea 右键没有class文件的问题,,
修改文件夹的 属性 蓝色即为java代码,,绿色为test,,等等
- kindeditor加入方法
1.editor文件夹拷进来 2. editor里jsp子文件夹里找到几个jar拷贝到网站的web-app里的lib下 3. 网页里 head里加个这个 <link rel="sty ...
- Java HashMap问题
1:map集合简述: 我们常用的集合实现类有HashMap.LinkedHashMap.TreeMap,HashTable.HashMap根据key的hashCode值来保存value ...
- Xversion for Mac优秀的SVN客户端功能特色介绍
xversion for mac是一款专为macOS打造的svn客户端,该软件拥有一个设计精美的界面以及全面的功能,简介的用户界面可以让您做到无需浏览用户手册即可熟练使用.xversion支持从最开始 ...
- Delphi 鼠标控制函数GetCursorPos、SetCursorPos
GetCursorPos函数 获取鼠标的位置 var P: TPoint; begin GetCursorPos(P); //获取鼠标位置 end; SetCursorPos函数 设置鼠标的位置 v ...
- SQL 在表中插入
SQL INSERT INTO 语句(在表中插入) INSERT INTO 语句用于向表中插入新记录. SQL INSERT INTO 语句 INSERT INTO 语句用于向表中插入新记录. SQL ...
- 【NOI2011】兔农(循环节)
我居然没看题解瞎搞出来了? 题解: 不难想到找到每次减1的位置,然后减去它对最终答案的贡献. 假设有一个地方是\(x,1(mod~k)\) 那么减了1后就变成了\(x,0\). 然后可以推到\(x,0 ...
- 实战:基于 Spring 的应用配置如何迁移至阿里云应用配置管理 ACM
最近遇到一些开发者朋友,准备将原有的Java Spring的应用配置迁移到 阿里云应用配置管理 ACM 中.迁移过程中,遇到不少有趣的问题.本文将通过一个简单的样例来还原迁移过程中遇到的问题和相关解决 ...
- jdk环境配置-windows 10
近期由于云服务器到期,重新买了一个云服务器,这里顺便把jdk环境配置步骤做一个记录 1.下载自己需要的jdk 我这里是下的免安装版的 2.计算机(此电脑)->属性->高级系统设置-> ...