使用带有 Java17 和 Spring Boot 3.0.0 的全新 Spring Initialzr,以及 Springfox Swagger 3 的 pom.xml 的额外补充,我一生都无法让 Swagger 页面工作。相反,我得到了带有 404 的白标错误页面。
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
本节中定义的标准 Swagger URLGithub 问题页面 https://github.com/springfox/springfox/issues/3441不适用于上述 pom.xml 项目。
在发布问题后我已经放弃并转而使用Spring Boot 2.7。但是,在看到 Dmitriy 的回答后,我最后一次检查了 Springdoc 并发现Springdoc v2 确实支持 Spring Boot 3 https://springdoc.org/v2/.
本质上,必须将以下内容放入其 pom 中:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.0</version>
</dependency>
然后可以使用以下 URL 访问 Swagger 页面:http://localhost:8080/swagger-ui.html(如果需要,请不要忘记添加上下文路径)。由于某种原因,打开时,它会重定向到 http://localhost:8080/swagger-ui/index.html,尽管最初返回的是 404...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)