Failed to start bean ‘documentationPluginsBootstrapper‘; nested exception is java.lang.NullPointerEx

一、报错问题

报错信息:
Failed to start bean ‘documentationPluginsBootstrapper’; nested exception is java.lang.NullPointerException
报错信息

二、问题发生背景

Spring Boot 整合 Swagger,用于生成 Web API 文档。

版本信息:spring boot:2.7.6,swagger:2.8.0

三、原因分析

springboot 升级到 2.6.0之后,swagger版本和springboot出现了不兼容情况,因为SpringBoot处理映射匹配的默认策略发生变化:

请求路径与 Spring MVC 处理映射匹配的默认策略已从AntPathMatcher更改为PathPatternParser

1. springboot 2.6.0之前:

public static class Pathmatch {
	private MatchingStrategy matchingStrategy = MatchingStrategy.ANT_PATH_MATCHER;
}

2.springboot2.6.0之后

public static class Pathmatch {
    private MatchingStrategy matchingStrategy = MatchingStrategy.PATH_PATTERN_PARSER;
}

四、解决方案

方案一:修改配置文件(最优,亲测

升级springboot到2.6之后,需要修改配置文件来兼容Swagger2
application.properties:

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

application.yml:

spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher

方案二:统筹规划SpringBoot和Swagger版本

swagger版本问题,升级3.0版本

或者

降低Spring Boot 版本,比如可以考虑将Spring Boot版本降低为2.5.6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值