我创建了一个简单的 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
我已使用以下 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
但是当我尝试使用以下 url http://192.168.254.94:30001/swagger-ui/index.html 访问我的 Springboot 的 swagger-ui 时我看到下面的 Whilelabel 错误页面
当我使用集群主节点 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/