Springboot整合swagger中遇到的错误

启动报错

Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

这个呢是因为springboot2.6更改了请求路径与与SpringMVC路径匹配规则,已经不是原来的AntPathMatcher了,改为了PathPatternParser。可能swagger3.0的一些地址还没作出相应的更新所以出错了。

解决的方法呢就是:

yml

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

现在我们终于是解决了springboot整合swagger后报错的问题了,但是来到了下一个问题springboot启动是启动了但是呢我们却访问不了。 

依赖不够 

对于依赖呢swagger3.0需要3个依赖而swagger2.0只需要两个依赖。

        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>3.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.springfox/springfox-boot-starter -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>

在我们使用swagger的过程中这些依赖是必须的

我们用的时候是使用java配置swagger所以

 这两个注解是必须的

@Configuration
@EnableOpenApi

现在我们能来尝试启动swagger然后打开页面文档了

如果你按照我的步骤来的话应该是这样的完全启动了这个教程非常新你也不用怕教程太老版本不匹配的问题

访问swagger文档

还有一件事

swagger3.0访问后台地址:http://localhost:8080/swagger-ui/index.html

访问地址跟2.0的不一样了请用这个地址

好了中遇到了我们的启动环节了

如果没有错的话你应该啊能看到这个页面,那么恭喜你已经成功的整合了swagger

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CodeForWater

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值