Springboot 2.6.2整合swagger2报错问题

我们经常使用这个swagger2来测试接口,swagger2可以快速的编写API接口文档,但是使用这个swagger2的时候,与springboot整合时,有可能会出现问题。我就遇上了这样一个问题,我使用的是Spring Boot Starter Swagger​的依赖:

 <!-- https://mvnrepository.com/artifact/com.spring4all/swagger-spring-boot-starter -->
        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>2.0.2.RELEASE</version>
        </dependency>

在配置文件中,配置也是没有任何的问题

#swagger配置
swagger:
  base-package: com.wang.demo01.member.controller
  title: "会员模块-swagger"
  description: "描述"
  version: "2.0"
  contact:
    name: "test"
    email: "test@163.com"
    url: "https://www.baidu.com"
  terms-of-service-url: "服务条款:https://www.baidu.com"

启动类上加上这个@EnableSwagger2

@SpringBootApplication
@MapperScan("com.wang.demo01.member.dao")
@EnableSwagger2
public class Demo01Application {

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

}

总体上看似乎没有问题,但是启动的时候,报了以下的错误

 因为这个错误,找了许久也浪费了好多时间,最后发现是springboot与swagger发生版本不兼容的问题。主要有两个解决的方案。

方案一:在xxx.yml文件中

加上:

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

如果是xxx.properties文件中加上:

spring: mvc: pathmatch: matching-strategy: ANT_PATH_MATCHER

方案二:springboot降级

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.7</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值