问题记录-SpringBoot 2.7.2 整合 Swagger 报错

详细报错如下

报错背景,我将springboot从2.3.3升级到了2.7.2,报了下面的错误:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerExceptionat org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.22.jar:5.3.22]at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) ~[spring-context-5.3.22.jar:5.3.22]at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.3.22.jar:5.3.22]at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_372]at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) ~[spring-context-5.3.22.jar:5.3.22]at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) ~[spring-context-5.3.22.jar:5.3.22]at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) ~[spring-context-5.3.22.jar:5.3.22]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.22.jar:5.3.22]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.2.jar:2.7.2]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.2.jar:2.7.2]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.2.jar:2.7.2]at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.2.jar:2.7.2]at com.yong.TemplateApplication.main(TemplateApplication.java:35) [classes/:na]
Caused by: java.lang.NullPointerException: nullat springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56) ~[springfox-spring-webmvc-3.0.0.jar:3.0.0]at springfox.documentation.RequestHandler.sortedPaths(RequestHandler.java:113) ~[springfox-core-3.0.0.jar:3.0.0]at springfox.documentation.spi.service.contexts.Orderings.lambda$byPatternsCondition$3(Orderings.java:89) ~[springfox-spi-3.0.0.jar:3.0.0]at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469) ~[na:1.8.0_372]at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355) ~[na:1.8.0_372]at java.util.TimSort.sort(TimSort.java:220) ~[na:1.8.0_372]at java.util.Arrays.sort(Arrays.java:1512) ~[na:1.8.0_372]at java.util.ArrayList.sort(ArrayList.java:1464) ~[na:1.8.0_372]at java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:392) ~[na:1.8.0_372]at java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:1.8.0_372]at java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:1.8.0_372]at java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:1.8.0_372]at java.util.stream.Sink$ChainedReference.end(Sink.java:258) ~[na:1.8.0_372]at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:483) ~[na:1.8.0_372]at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[na:1.8.0_372]at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_372]at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_372]at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) ~[na:1.8.0_372]at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:81) ~[springfox-spring-webmvc-3.0.0.jar:3.0.0]at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_372]at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384) ~[na:1.8.0_372]at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[na:1.8.0_372]at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[na:1.8.0_372]at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_372]at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_372]at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) ~[na:1.8.0_372]at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.withDefaults(AbstractDocumentationPluginsBootstrapper.java:107) ~[springfox-spring-web-3.0.0.jar:3.0.0]at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.buildContext(AbstractDocumentationPluginsBootstrapper.java:91) ~[springfox-spring-web-3.0.0.jar:3.0.0]at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.bootstrapDocumentationPlugins(AbstractDocumentationPluginsBootstrapper.java:82) ~[springfox-spring-web-3.0.0.jar:3.0.0]at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:100) ~[springfox-spring-web-3.0.0.jar:3.0.0]at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) ~[spring-context-5.3.22.jar:5.3.22]... 12 common frames omittedDisconnected from the target VM, address: '127.0.0.1:63816', transport: 'socket'Process finished with exit code 1

排查:
跟踪到时这里空指针WebMvcPatternsRequestConditionWrapper#getPatterns
在这里插入图片描述
这里之所以为空是因为,这里走了PATH_PATTERN_PARSER默认走的是这个策略:
在这里插入图片描述

走这个默认策略就会设置WebMvcAutoConfiguration#configurePathMatch,然后调用setPatternParser
在这里插入图片描述

然后子build逻辑的时候,如果patternParser不为空则走上面的分支,所以PatternsRequestCondition 不会赋值,所以下面使用就报错了空指针:
在这里插入图片描述
所以我们再结合上面,的分析我们追踪到可以通过配置改变这个策略,到此位置问题解决:

spring:mvc:pathmatch:matching-strategy: ant_path_matcher

但是为很好奇为什么springboot2.3.3就不会有这个问题呢?整合方式没有变呀,那只能去源码找答案了。你会发现你找不到MatchingStrategy,下面的代码如果不配置默认就是AntPathMatcher,到这里就明显了所以2.3.3没有报错。

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/47997.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

信息收集Part3-资产监控

Github监控 便于收集整理最新exp或poc 便于发现相关测试目标的资产 各种子域名查询 DNS,备案,证书 全球节点请求cdn 枚举爆破或解析子域名对应 便于发现管理员相关的注册信息 通过Server酱接口接收漏洞信息 https://sct.ftqq.com/ https://github.com/easych…

从苏宁电器到卡巴斯基(第二部)第36篇:我当高校教师的这几年 XII

你们是八九点钟的太阳 想想也是有趣,自从我2018年3月入职X高校之后,一直到2019年9月,在这3个学期的时间里面,我讲课的对象全都是大三的同学,而且都是属于专业方向课,比如网络安全、物联网这种。第一学期尽管也教过C++,但是他们毕竟已经是大三第二学期,从心态上来说,他…

2024.7.23(DNS正向解析)

回顾: # 安装 samba yum -y install samba # 自建库,只下载,不安装 yum -y install --downloadonly --downloaddir./soft/ # 配置samba vim /etc/samba/smb.conf # 配置 [xxxxxxxname] commentdasdffsffdslfdjsa path/share …

h5点击电话号跳转手机拨号

需要使用到h5的 <a>标签 我们首先在<head>标签中添加代码 <meta name"format-detection" content"telephoneyes"/>然后再想要的位置添加代码 <a href"tel:10086"> 点击拨打&#xff1a;10086 </a> 这样功能就实现…

海量数据处理(面试)

海量数据 1、从大量的URL中找出相同的URL 解法&#xff1a; 分治法&#xff1a; 如果是单个很大的文件&#xff0c;直接划分文件&#xff0c;按特定大小划分&#xff0c;然后多线程&#xff0c;用map对各个文件进行统计。 如果是两个很大的文件&#xff0c;a和b。通过遍历a…

如何在Linux上安装配置Nexus私有仓库

在Linux上安装和配置Nexus私有仓库需要以下步骤&#xff1a; 下载Nexus Repository Manager&#xff1a; 首先&#xff0c;访问Sonatype Nexus官方网站&#xff08;https://www.sonatype.com/nexus-repository-oss&#xff09;并下载适用于Linux的最新版本的Nexus Repository M…

系统架构设计师教程 第4章 信息安全技术基础知识-4.3 信息安全系统的组成框架4.4 信息加解密技术-解读

系统架构设计师教程 第4章 信息安全技术基础知识-4.3 信息安全系统的组成框架 4.3 信息安全系统的组成框架4.3.1 技术体系4.3.1.1 基础安全设备4.3.1.2 计算机网络安全4.3.1.3 操作系统安全4.3.1.4 数据库安全4.3.1.5 终端安全设备4.3.2 组织机构体系4.3.3 管理体系4.4 信息加…

redis命令超详细

redis数据结构介绍 redis是一个key-value的数据库&#xff0c;key一般是String类型&#xff0c;但是value的类型有很多&#xff1a; 基本类型&#xff1a;String,Hash,List,Set,SortedSet(可排序的不能重复的集合) 特殊类型&#xff1a;GEO,BitMap,HyperLog等 文档官网&…

使用编译器指令将此函数定位在指定地址处

#include <stdio.h> // 使用编译器指令将此函数定位在0x08001000地址处 void my_function() attribute((section(“.ARM.__at_0x08001000”))); void my_function() { printf(“Function located at 0x08001000\n”); } int main() { my_function(); return 0; }

emr部署hive并适配达梦数据库

作者&#xff1a;振鹭 一、达梦 用户、数据库初始化 1、创建hive的元数据库 create tablespace hive_meta datafile /dm8/data/DAMENG/hive_meta.dbf size 100 autoextend on next 1 maxsize 2048;2、创建数据库的用户 create user hive identified by "hive12345&quo…

Android --- 广播

广播是什么&#xff1f; 一种相互通信&#xff0c;传递信息的机制&#xff0c;组件内、进程间&#xff08;App之间&#xff09; 如何使用广播&#xff1f; 组成部分 发送者-发送广播 与启动其他四大组件一样&#xff0c;广播发送也是使用intent发送。 设置action&#xff…

如何在Ubuntu上安装并启动SSH服务(Windows连接)

在日常的开发和管理工作中&#xff0c;通过SSH&#xff08;Secure Shell&#xff09;连接到远程服务器是一个非常常见的需求。如果你在尝试通过SSH连接到你的Ubuntu系统时遇到了问题&#xff0c;可能是因为SSH服务未安装或未正确配置。本文将介绍如何在Ubuntu上安装并启动SSH服…

高效工作流:用Mermaid绘制你的专属流程图;如何在Vue3中导入mermaid绘制流程图

目录 高效工作流&#xff1a;用Mermaid绘制你的专属流程图 一、流程图的使用场景 1.1、流程图flowChart 1.2、使用场景 二、如何使用mermaid画出优雅的流程图 2.1、流程图添加图名 2.2、定义图类型与方向 2.3、节点形状定义 2.3.1、规定语法 2.3.2、不同节点案例 2.…

背包问题模板

2. 01背包问题 - AcWing题库 #include<bits/stdc.h> using namespace std; const int N1010; int f[N]; int v[N],w[N];int main() {int n,m;cin>>n>>m;for(int i1;i<n;i){cin>>v[i]>>w[i];}for(int i1;i<n;i)for(int jm;j>v[i];j--)…

Unity扩展 UI线段绘制组件——UI上的LineRenderer

原理&#xff1a; 利用 Graphic 类重写 OnPopulateMesh 方法类绘制自定义顶点的面片从而组成一条线。 MaskableGraphic 类继承自 Graphic&#xff0c;并且可以实现“可遮罩图形”&#xff0c;方便在列表中使用。 绘制图形API&#xff1a; // 添加顶点&#xff0c;第一个添加…

golang 字符编码 gbk/gb2312 utf8编码相互转换,判断字符是否gbk编码函数, 字符编码转换基础原理解析, golang默认编码utf8

虽然golang里面的默认编码都是统一的unicode utf8编码&#xff0c; 但是我们在调用外部系统提供的api时&#xff0c;就可能会遇到别人的接口提供的编码非 utf8编码&#xff0c;而是gbk/gb2312编码&#xff0c; 这时候我们就必须要将别人的gbk编码转换为go语言里面的默认编码ut…

2024年7月22日(nfs samba)

一、webserver 服务器&#xff1a;作用是发布nginx的web项目 1、安装nginx&#xff08;只下载不安装&#xff09; [rootweb_server ~]# yum -y install --downloadonly --downloaddir./soft/ nginx 2、配置一个本地的nginx仓库 [rootweb_server ~]# yum -y install createrepo…

45、PHP 实现滑动窗口的最大值

题目&#xff1a; PHP 实现滑动窗口的最大值 描述&#xff1a; 给定一个数组和滑动窗口的大小&#xff0c;找出所有滑动窗口里数值的最大值。 例如&#xff1a; 如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3&#xff0c; 那么一共存在6个滑动窗口&#xff0c; 他们的最大值…

微服务

微服务架构是一种设计方法&#xff0c;它将应用程序划分为一组独立的、可互相调用的服务&#xff0c;每个服务对应一个具体的业务功能。以下是微服务的一些关键知识点总结&#xff1a; 1. 微服务的基本概念 服务组件化&#xff1a;将应用程序分解为多个小的、独立的组件&…

基于vue3 + vite产生的 TypeError: Failed to fetch dynamically imported module

具体参考这篇衔接&#xff1a; Vue3报错&#xff1a;Failed to fetch dynamically imported module-CSDN博客 反正挺扯淡的&#xff0c;错误来源于基于ry-vue-plus来进行二次开发的时候遇到的问题。 错误起因 我创建了一个广告管理页面。然后发现访问一直在加载中。报的是这样…