SpringBoot无法访问swagger-ui.html (404),已解决

本文档展示了如何在SpringBoot项目中集成Swagger3.0.0,通过配置类SwaggerConfig进行API文档的创建。配置包括指定扫描的基础包、API信息以及访问路径。访问地址为http://localhost:8080/swagger-ui/index.html,可以用于测试和展示RESTful API。
摘要由CSDN通过智能技术生成

目前我集成的是Swagger 3.0.0

这是集成代码


        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        

写一个配置类 SwaggerConfig

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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
public class SwaggerConfig {

    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.liuyun.longmian";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
              .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()//页面标题
                .title("Spring Boot中使用Swagger2构建RESTFUL API")//描述
                .description("欢迎来到傅鹏程的博客")
                .termsOfServiceUrl("https://blog.csdn.net/v2810769")//地址
                .version("1.0")
                .build();
    }

}

访问地址是 http://localhost:8080/swagger-ui/index.html

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值