[一招解决]SpringBoot集成Swagger3.0报错java.lang.NullPointerException

       都说用新不用旧,但是对于高速迭代的springboot新版本来说集成其他框架经常会出现一些问题。今天使用springboot集成swagger3.0启动就报错:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

解决办法有三种:

  1. 将swagger版本降为2.9.2,maven坐标为:
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger2</artifactId>
   <version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
   <groupId>io.springfox</groupId>
   <artifactId>springfox-swagger-ui</artifactId>
   <version>2.9.2</version>
</dependency>
  1. 将springboot的版本降为2.5.7后重新启动项目(听说可以)
    并将@EnableSwagger2注解改为@EnableOpenApi即可
  2. 我就想使用swagger3.0还要使用springboot2.6也行:
        找了一会终于找到一个解决方案:
    在这里插入图片描述
    后来查了一下资料了解到:springboot2.6更改了请求路径与与SpringMVC路径匹配规则,已经不是原来的AntPathMatcher了,改为了PathPatternParser。可能swagger3.0的一些地址还没作出相应的更新所以出错了。只需在配置文件加上一句:
spring.mvc.pathmatch.matching-strategy=ant_path_matcher

如果你的配置文件是yaml:

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

补充:
swagger3.0访问后台地址:http://localhost:8080/swagger-ui/index.html
swagger3.0以下:http://localhost:8080/swagger-ui.html
别忘了swagger3.0要将@EnableSwagger2注解改为@EnableOpenApi

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值