簡體   English   中英

Spring Boot 3 springdoc-openapi-ui 不工作

[英]Spring Boot 3 springdoc-openapi-ui doesn't work

我正在嘗試將 swagger-ui (OpenAPI 3.0) 添加到 Spring Boot v3 應用程序。

我已經添加了 openapi-ui maven 依賴項,它應該按照文檔工作。

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

但顯然,它仍然不起作用,並且 localhost:8080/swagger-ui.html 返回 404 錯誤。

我錯過了什么?

在此處輸入圖像描述

根據文檔:

對於spring-boot 3支持,請確保使用springdoc-openapi v2

https://springdoc.org/v2/

spring-boot 和 swagger-ui 的集成,將庫添加到你的項目依賴列表中(不需要額外配置)

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

這將自動將 swagger-ui 部署到 spring-boot 應用程序:

文檔將以 HTML 格式提供,使用官方的 swagger-ui jar

然后 Swagger UI 頁面將在http://server:port/context-path/swagger-ui.html可用,OpenAPI 描述將在以下 json 格式的 url 可用: http://server:port/context-path/v3/api-docs

server: The server name or IP

port: The server port

context-path: The context path of the application

Documentation can be available in yaml format as well, on the following path : /v3/api-docs.yaml

請注意,模塊已重命名:

https://springdoc.org/v2/#migrating-from-springdoc-v1

在此處輸入圖像描述

對我有幫助,只是改變了依賴性

   implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.11'

    implementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-ui', version: '2.0.0'

要么

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

我完全同意@JCompetence。 請注意, springdoc-openapi-ui現在從 spring boot 3 更改為springdoc-openapi-starter-webmvc-ui

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

請試試這個。 如果您想查找更多信息,請查看官方鏈接: https ://springdoc.org/v2/#features

在包含“spring-boot-starter-web”之前,“springdoc-openapi-starter-webmvc-ui”不能與“spring-boot-starter-webflux”一起使用。 如果您包括 spring 安全性,那么它就死了。

Maven 從 OpenApi 規范(.yml 文件)生成 (Java) 代碼的插件

生成器“spring”支持 Jakarta 命名空間

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
    <configuration>
        <configOptions>
            ...
            **<useSpringBoot3>true</useSpringBoot3>**
        </configOptions>
    </configuration>
</plugin>

生成器“java”(用於生成客戶端)尚不支持 Jakarta 命名空間。 所以使用 Eclipse Transformer 插件(需要提供 Javax 依賴范圍!)

 <plugin>
        <groupId>org.eclipse.transformer</groupId>
        <artifactId>transformer-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <rules>
           <jakartaDefaults>true</jakartaDefaults>
         </rules>
       </configuration>
        <executions>
            <execution>
                <id>jakarta-ee</id>
                <goals><goal>jar</goal></goals>
                <phase>package</phase>
                <configuration>
                    <artifact>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                    </artifact>
                </configuration>
            </execution>
        </executions>
    </plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM