【问题标题】:Cannot open swagger-ui with the usage of Openapi in Spring Boot 3 (Whitelabel Error Page)无法在 Spring Boot 3 中使用 Openapi 打开 swagger-ui(Whitelabel 错误页面)
【发布时间】:2023-02-09 16:41:00
【问题描述】:

我在 Spring Boot 中通过 Openapi 打开 swagger-ui 时遇到问题。

当我尝试打开此 URL http://localhost:8080/swagger-ui.html 时,我得到白标错误页面

我该如何解决这个问题?

这里是依赖定义于pom.xml如下所示。

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.4</version>
</dependency>

这里是openpi配置类如下所示。

@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI customOpenAPI(@Value("${application-description}") String description,
                                 @Value("${application-version}") String version) {
        return new OpenAPI()
                .info(new Info().title("API")
                        .version(version)
                        .description(description)
                        .license(new License().name("API Licence")));
    }
}

这是如下所示的 application.properties 文件。

springdoc.swagger-ui.path=/swagger-ui.html
application-description=API Description
application-version=1.0

logging.level.org.springframework.web=DEBUG
logging.level.io.springfox=DEBUG

这是当我尝试打开此 URL http://localhost:8080/swagger-ui.html 时显示的错误

2023-02-09T08:36:16.593+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : GET "/swagger-ui.html", parameters={}
2023-02-09T08:36:16.594+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/], ServletContext [/]]
2023-02-09T08:36:16.596+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2023-02-09T08:36:16.596+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Completed 404 NOT_FOUND
2023-02-09T08:36:16.597+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for GET "/error", parameters={}
2023-02-09T08:36:16.597+03:00 DEBUG 20184 --- [nio-8080-exec-4] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest, HttpServletResponse)
2023-02-09T08:36:16.599+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html, text/html;q=0.8]
2023-02-09T08:36:16.599+03:00 DEBUG 20184 --- [nio-8080-exec-4] o.s.web.servlet.DispatcherServlet        : Exiting from "ERROR" dispatch, status 404

我该如何解决这个问题?

这是回购协议:Link

【问题讨论】:

  • 您是否在没有 customOpenAPI bean 的情况下尝试过?
  • @sge 我测试了它但没有任何改变。如果您不介意,可以帮我测试一下吗?

标签: java spring-boot swagger-ui openapi springdoc-openapi-ui


【解决方案1】:

您需要为 Spring Boot 3 使用不同的依赖项:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.2</version>
</dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 2014-10-10
    相关资源
    最近更新 更多