栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Swagger 3.0 问题

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Swagger 3.0 问题

1,导入环境

        
            io.springfox
            springfox-swagger2
            3.0.0
        
        
            io.springfox
            springfox-swagger-ui
            3.0.0
        
        <--启动包-->
        
            io.springfox
            springfox-boot-starter
            3.0.0
        

这个时候springboot会报错!!!
解决方法

解决方式1:把springboot的版本降到2.5-版本的

解决方式2:直接修改配置spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER来更改规则(在properties文件或者yml都可)

原因:这是因为Springfox使用的路径匹配是基于AntPathMatcher的, 而Spring Boot 2.6.X使用的是PathPatternMatcher。


你们以为就完了?不还没有!!!!!

环境配置好了你会发现,当你输入http://localhost:8080/swagger-ui.html会报404,这是因为3.0里的访问地址变了

SwaggerConfig.java 配置

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2//启用swagger
public class SwaggerConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.
                addResourceHandler( "/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
    }
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController( "/swagger-ui/")
                .setViewName("forward:" +  "/swagger-ui/index.html");
    }
}

这里是官方文档说明:Springfox Reference Documentation

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/821151.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号