spring-boot - 使用K8S IP和Nodeport访问时Springboot Swagger Ui抛出Whitelabel错误页面

标签 spring-boot kubernetes springdoc-openapi-ui service-node-port-range

我创建了一个简单的 Springboot 应用程序,该应用程序在我的本地主机端口号 9091 上运行,返回“Hello world!!!”当调用 http://localhost:9091/helloWorld url 时。

下面是我的Springboot主类和 Controller 类的代码片段

@SpringBootApplication
public class HelloWorldApplication {

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

}

@RestController
public class HelloWorldController {
    
    @GetMapping(value="/helloWorld")
    public String helloWorld() {
        return "Hello world!!!!";
    }

}

下面是我的 pom.xml 中的依赖项

        <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.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.3</version>
        </dependency>

我还可以使用以下 URL http://localhost:9091/swagger-ui/index.html 访问 Springboot 项目的 swagger ui

Swagger UI Accessed on Localhost

我已使用以下 yaml 文件配置将此 Springboot 应用程序部署到我的 k8s 集群中

apiVersion: apps/v1
kind: Deployment
metadata:
   name: hello-world
spec:
   replicas: 1
   selector:
      matchLabels:
         app: hello-world
   template:
      metadata:
        labels:
           app: hello-world
      spec:
         containers:
            - name: hello-world
              image: moviepopcorn/hello_world:0.0.1
              ports:
                 - containerPort: 9091
              imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
   name: hello-world
spec:
   type: NodePort
   selector:
      app: hello-world
   ports:
      - port: 9091
        targetPort: 9091
        nodePort: 30001

我还可以使用以下 URL : 访问 helloWorld 端点,如下所示

Node port service accessed on a browser

但是当我尝试使用以下 url http://192.168.254.94:30001/swagger-ui/index.html 访问我的 Springboot 的 swagger-ui 时我看到下面的 Whilelabel 错误页面

Whitelabel Error Page

当我使用集群主节点 IP 访问我的 springboot 应用程序时,您能否帮助我了解导致此 Whitelabel 错误页面问题的原因?

最佳答案

我找到了这个问题的解决方案。我刚刚在 pom.xml 中添加了以下依赖项

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

关于spring-boot - 使用K8S IP和Nodeport访问时Springboot Swagger Ui抛出Whitelabel错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71133895/

相关文章:

kubernetes - 如何获取 kubernetes pod 的公共(public) ip?

spring-boot - Spring-Doc open api 无法与 Spring cloud 配置服务器 @EnableConfigServer 一起使用

java - Spring MVC 将 406 返回到 Controller 测试

spring - 如何在 Junit 测试中更改代码中的 Spring 属性文件变量?

java - Spring Boot Controller 的 catch block 的 JUnit5 测试覆盖率

docker - 尝试使用 helm/docker 查找本地镜像时出现错误

java - 由于自定义约束 validator , validator 单元测试失败

docker - 部署,服务,入口已实现。有默认后端-404

java - 授权 header 未显示在 CURL springdoc-openapi-ui 中

springdoc-openapi-ui - 无法在端口 9001 : Could not invoke shutdown operation: 连接到 MBean 服务器