我创建了一个简单的 Springboot 应用程序,它在我的本地主机端口号 9091 上运行,返回“Hello world!!!”当调用 http://localhost:9091/helloWorld url 时。
下面是我的Springboot主类和控制器类的代码片段
@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 访问 helloWorld 端点
但是当我尝试使用以下网址访问 Springboot 的 swagger-ui http://192.168.254.94:30001/swagger-ui/index.html 我看到下面的 Whilelabel 错误页面
当我使用集群主节点 IP 访问我的 springboot 应用程序时,您能否帮助我了解导致此 Whitelabel 错误页面问题的原因?
我找到了解决方案。我刚刚在 pom.xml 中添加了以下依赖项
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webflux-ui</artifactId>
<version>1.6.3</version>
</dependency>
一般来说,只需添加
springdoc-openapi-starter-webmvc-ui
依赖项就可以了。但是,如果您发现从 IntelliJ 内部启动 Spring Boot 时出现Whitelabel 错误页面,请尝试以下操作:
mvn clean install -DskipTests