无法在 Spring Boot 3 中使用 Openapi 打开 swagger-ui(Whitelabel 错误页面)

2 java swagger-ui spring-boot openapi springdoc-openapi-ui

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

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

我该如何解决这个问题?

这是pom.xml中定义的依赖项,如下所示。

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

这是如下所示的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")));
    }
}
Run Code Online (Sandbox Code Playgroud)

这是如下所示的 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
Run Code Online (Sandbox Code Playgroud)

当我尝试打开此 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
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

这是回购协议:链接

Tim*_*mes 5

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

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.3.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

在此处查找当前版本。