I have a Spring Boot + Spring Cloud application that I'd like to build as a native image for faster startup time and smaller image size. I understand that Spring Cloud is not yet providing official support for native images, so I'm manually registering hints for reflection using Spring's RuntimeHintsRegistrar
during AOT processing.
Now I'm able to build a native image with gradle bootBuildImage
, but when I deploy the image to Kubernetes it fails with this error:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method kubernetesPodUtils in .springframework.cloud.kubernetes.fabric8.Fabric8AutoConfiguration required a single bean, but 2 were fou
- kubernetesClient: defined in unknown location
- configKubernetesClient: a programmatically registered singleton
The kubernetesClient
bean is provided in Fabric8AutoConfiguration
, while configKubernetesClient
is registered programmatically in Fabric8ConfigDataLocationResolver
.
This does not happen if I deploy a non-native image of the same exact application, so I guess it's the AOT processing that is missing something.
The app depends on spring-cloud-starter-kubernetes-fabric8-config
and has the following properties set:
spring.config.import=kubernetes:
spring.cloud.kubernetes.config.reload.enabled=true
Why does this happen in the native image? Is the AOT processing missing some hint that I can register manually? I know I can workaround this by providing yet another KubernetesClient
bean in my app code and annotate it with @Primary
, but I'd prefer to use the one provided by Spring Cloud and not override it.