Swagger 3 在 SpringBoot 3 中获取 Whitelabel 错误页面

问题描述 投票:0回答:2

我正在 Springboot 3 中制作 API。当我添加此 dependency 时,我在 http://localhost:8080/swagger-ui/index.html 或其他链接处收到白标签错误页面。我还添加了@EnableWebMvc @ComponentScan(basePackages = {"org.springdoc"}) @SpringBootApplication注释,但他们没有解决我的问题。

我的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.1.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>codding</groupId>
    <artifactId>userDataBase</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>userDataBase</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-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

我的应用程序java文件:

package coding.userDataBase;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class UserDataBaseApplication {

    public static void main(String[] args) {
        SpringApplication.run(UserDataBaseApplication.class, args);
    }

}

如何解决 springboot 3 中的 swagger 3 出现白标错误。谢谢大家顺便说一句。

spring spring-boot swagger backend swagger-ui
2个回答
0
投票

从 pom.xml 中删除其他 swagger 依赖项并使用它:

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

0
投票

一般来说,接受的答案应该有效。但是,如果您发现从 IntelliJ 内部启动 Spring Boot 时出现Whitelabel 错误页面,请尝试以下操作:

  • 转到文件 > 使缓存无效...,然后单击使缓存无效并重新启动
  • 在终端中,执行
    mvn clean install -DskipTests
  • 重新启动您的应用程序
  • 尝试访问 http://localhost:8080/[context-root]/v3/api-docs 或 http://localhost:8080/[context-root]/swagger-ui/index.html 这对我有用(经过几个小时的谷歌搜索)...
© www.soinside.com 2019 - 2024. All rights reserved.