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

SpringBoot之整合Swagger(页面无法显示)

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

SpringBoot之整合Swagger(页面无法显示)

问题: 配置Swagger后,访问http://localhost:8080/swagger-ui.html不显示页面 原因:Swagger版本过高

我尝试降低springboot版本到2.2.6.RELEASE结果还是不行,然后将Swagger版本从3.0降到2.9.2就可以访问了,随后我又将springboot版本还原,还是可以访问,最后得出Swagger版本不能太高

1、添加依赖
 
        
            io.springfox
            springfox-swagger2
            2.9.2
        
        
            io.springfox
            springfox-swagger-ui
            2.9.2
        

2、配置Swagger

package com.liu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启了swagger2
public class SwaggerConfig {
    //配置了swagger的Docker的bean实例
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //包下的类,生成接口文档
                .build();
    }

    //配置Swagger信息
    private ApiInfo apiInfo() {
//        作者信息
        Contact contact = new Contact("小柳", "https://www.baidu.com", "1811961890@qq.com");
        return new ApiInfoBuilder()
                .contact(contact)
                .title("充电了")
                .description("打卡!!!")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0")
                .build();
    }
}

3、配置Controller

package com.liu.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {

    @RequestMapping("/hello")
    public String hello(){
        return "欢迎使用!!!!";
    }
}

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

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

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