spring.cloud.kubernetes.discovery-server-url必须指定,



我正在更新服务的依赖关系,从Spring Boot2.3.12.RELEASE2.7.0,从Spring CloudHoxton.Release2021.0.3

这样做后,我开始得到kubernetes错误,我没有看到在以前的依赖版本。

nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'compositeDiscoveryClient' defined in class path resource [org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientAutoConfiguration.class]: Unsatisfied dependency expressed through method 'compositeDiscoveryClient' parameter 0; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kubernetesDiscoveryClient' defined in class path resource [org/springframework/cloud/kubernetes/discovery/KubernetesDiscoveryClientAutoConfiguration$Servlet.class]: Bean instantiation via factory method failed; 
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.client.discovery.DiscoveryClient]: Factory method 'kubernetesDiscoveryClient' threw exception; 
nested exception is org.springframework.cloud.kubernetes.discovery.DiscoveryServerUrlInvalidException: spring.cloud.kubernetes.discovery-server-url must be specified and a valid URL.

我已经阅读了一些关于在应用程序中使用@EnableDiscoveryClient注释以及在控制器中自动连接DiscoveryClient的教程,包括Baeldung教程。但是,我还没有看到任何提到discovery-server-url的内容。

我在哪里设置这个值,或者我如何告诉Spring和Kubernetes寻找什么?

请注意"spring.cloud.kubernetes.discovery-server-url"在spring错误消息中有一个拼写错误。参数名称为spring.cloud.kubernetes.discovery.discovery-server-url

可以在spring的外部配置中任意位置设置。属性,.yaml)。关于k8,最快的方法可能是部署中的args。yaml:

template:
metadata:
labels:
...
spec:
containers:
- name: ...
image: ...
command: ["java"]
args: ["-Dspring.profiles.active=kubernetes", "-Dspring.cloud.kubernetes.discovery.discovery-server-url=http://spring-cloud-kubernetes-discoveryserver.default.svc.cluster.local", "-Dspring.cloud.kubernetes.discovery.enabled=true", "org.springframework.boot.loader.JarLauncher"]
ports:
...

最新更新