swagger3.0无法访问swagger后台

无法访问后台地址

首先swagger3.0后的访问地址为:http://localhost:8080/swagger-ui/index.html
以往的2.0的访问地址是http://localhost:8080/swagger-ui.html

问题原因:其次就是2.0需要导入2个包,而3.0需要导入三个包

<!-- 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-swagger2 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</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>

控制台报错

当控制台报错:fail to start bean 'documentationPluginBootstrapper';

解决办法:

spring:
 mvc:
  pathmatch:
   matching-strategy: ant_path_matcher

Springboot 2.6.x 版本都是基于path_pattern_matcher的,要使用swagger需要配置其为ant_path_matcher,但是如果你有使用Springboot的Actuator,那么Actuator就会失效,因为它是基于path_pattern_matcher的。如果有需要同时使用,则需进行兼容性代码修改(见下文链接)。
参考:https://blog.csdn.net/GeAhardaharvest/article/details/121739866
https://blog.csdn.net/u011943534/article/details/121656010

posted @ 2022-07-14 15:43  长情c  阅读(1378)  评论(0)    收藏  举报