首页 > 其他分享 >记一次SpringBoot Filter的过滤器被重复执行问题

记一次SpringBoot Filter的过滤器被重复执行问题

时间:2023-09-09 20:04:17浏览次数:70  
标签:SpringBoot color void Filter 过滤器 WebFilter public

记一次SpringBoot Filter的过滤器被重复执行问题

debug发现过滤器 执行两次,后来定位到WebFilter和Component注解导致多次扫描,而这次需要用到WebFilter,所以注掉了Component

@Order(0)
//@Component
@WebFilter(urlPatterns = {"/*"})
@ConditionalOnProperty(name = "color.trace.start", havingValue = "true")
public class ThreadFilter implements Filter {
    public ThreadFilter() {
        System.out.println("color.trace.start...");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse
            servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String requestId = StrUtils.genRequestId();
        ThreadLocalUtils.init(requestId);
        MDC.put(MDC_TRACE_ID,requestId);
        filterChain.doFilter(servletRequest, servletResponse);
        ThreadLocalUtils.close();
    }

    @Override
    public void destroy() {

    }
}

@EnableColorProxy
@ServletComponentScan("com.player3.color.filter")
@SpringBootApplication
public class EshopOrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(EshopOrderApplication.class, args);
    }

}

b站视频:https://www.bilibili.com/video/BV11u411w7U3/

标签:SpringBoot,color,void,Filter,过滤器,WebFilter,public
From: https://www.cnblogs.com/q1359720840/p/17690045.html

相关文章

  • SpringBoot如何让业务Bean优先于其他Bean加载
    本博客原文地址:https://ntopic.cn/p/2023090901/源代码先行:Gitee本文介绍的完整仓库:https://gitee.com/obullxl/ntopic-bootGitHub本文介绍的完整仓库:https://github.com/obullxl/ntopic-boot背景介绍今天走读一个应用程序代码,发现一个有趣的现象:有多个不同的业务Bean中均......
  • Spring,SpringMVC,SpringBoot,SpringCloud有什么区别?
    讲一讲Spring、SpringMVC、SpringBoot、SpringCloud之间的关系?Spring是核心,提供了基础功能;SpringMVC是基于Spring的一个MVC框架;SpringBoot是为简化Spring配置的快速开发整合包;SpringCloud是构建在SpringBoot之上的服务治理框架。Spring一般说Spring框架指......
  • SpringBoot框架实现一个简单的管理系统
    当然,我可以提供一个简单的示例代码,用SpringBoot框架实现一个简单的管理系统。以下是一个用户管理系统的示例代码:创建SpringBoot项目:使用SpringInitializr(https://start.spring.io/)创建一个新的SpringBoot项目,选择相应的依赖(如SpringWeb、SpringDataJPA、Thymeleaf等)。创建......
  • springboot 框架国际化 + thymeleaf
    项目目录结构注意:导入thymeleaf,web的pom依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency><dependency> <groupId>org.springframework.boot&l......
  • springboot打fat包怎么把第三方jar打入boot/lib中
    在maven工程的POM文件修改如下,在build部分: <resources><resource><directory>src/main/resources</directory></resource><resource><directory>../yhya-credibledata-collect-service/lib</directory>......
  • IntelliJ IDEA新建SpringBoot项目
    IntelliJIDEA新建SpringBoot项目前言虽然新建项目比较简单,但还是有几个点需要注意。步骤下载和安装IDEA不再介绍新建工程点击“NewProject”标红的为重点关注需要关注的几个字段:Name:项目/模块名Artifact:相当于具体的功能名Group:可以理解为分组,例如......
  • springboot简单使用poi-tl
    简介poi-tl是一个基于ApachePOI的开源Word模板引擎,比Freemarker的功能更加强大。官方文档地址:http://deepoove.com/poi-tl/导包导入包时,依赖说明参考官方文档,导入包不适配可能会造成一些问题,此处可以使用<dependency><groupId>org.apache.poi</grou......
  • 通过数组filter方法过滤数组中对象
    通过过滤器filter获取数组对象的属性名和属性值constarr=[{label:'张三',value:'111111',},{label:'李四',value:'22222',},]//通过filter过滤获取到新数组......
  • SpringBoot中配置文件和配置类实现个性化配置的一点区别
    先说配置文件,以properties文件为例,默认存放静态资源文件夹路径是 "classpath:/META-INF/resources/","classpath:/resources/","classpath:/static/","classpath:/public/"。经过下面配置后,这些默认规则都不再生效。#自定义静态资源文件夹位置spring.web.resources.static-locat......
  • 为什么 springboot 项目中 使用 lombok 不需要指定版本
    springboot默认管理了lombok的版本依赖,所以不需要指定版本号SpringBoot项目中使用Lombok不需要显式指定Lombok的版本,是因为SpringBoot的父项目(spring-boot-starter-parent)已经为您管理了Lombok的版本。这是通过在SpringBoot的父项目中的dependencyManagement部分指定Lombok的......