bootstrap ui 的 swagger 打不开提示资源接口问题

来源:2-5 配置接口文档生成利器-swagger2

无解的游戏

2023-07-24

图片描述

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
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;

/**
 * 接口文档配置类
 */
@SpringBootConfiguration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@Component
@Slf4j
public class Swagger2Config {

    @Autowired
    private Swagger2ConfigProperties properties;

    @Bean
    public Docket panServerApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .enable(properties.isShow())
                .groupName(properties.getGroupName())
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false)
                .select()
                .apis(RequestHandlerSelectors.basePackage(properties.getBasePackage()))
                .paths(PathSelectors.any())
                .build();
        log.info("The swagger have been loaded successfully");

        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(properties.getTitle())
                .description(properties.getDescription())
                .termsOfServiceUrl(properties.getTermsOfServiceUrl())
                .contact(new Contact(properties.getContactName(), properties.getContactUrl(), properties.getContactEmail()))
                .version(properties.getVersion())
                .build();
    }
}

不知道为啥访问http://127.0.0.1:端口/doc.html提示这个

后续使用,决定不使用 bootstrap 的 ui,使用knife4j的

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>2.0.1</version>
</dependency>

把原先的一些激活 bootstrap 的 ui 的注解删掉和依赖也一起删掉,然后直接启动就完了。

图片描述

而且觉得这个操作更爽快,更好看。

写回答

1回答

RubinChu

2023-07-25

看一下 show属性是不是设置成 false 了

0
5
无解的游戏
不用这个 UI 了,用 knife4j 的
2023-08-06
共5条回复

SpringBoot+Vue3+Element Plus打造私人分布式存储系统

SpringBoot+Vue3+Element Plus 仿百度网盘实战

274 学习 · 346 问题

查看课程