[英]Spring Cloud Config Server doens't work with Docker build
Hello and thanks for your attention.您好,感谢您的关注。 I got a problem trying to Dockerize my Spring Cloud Config Server using Git for managing my microservices, My app working oke when it's just Spring Cloud microservices context, but when i create the Dockerfile for this Config Server, and build-it: i got the next error:我在尝试使用 Git 对我的 Spring 云配置服务器进行 Dockerize 管理我的微服务时遇到问题,当它只是 Spring 云微服务上下文时,我的应用程序工作正常,但是当我为此配置服务器创建 Dockerfile 并构建它时:我得到了下一个错误:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configServerHealthIndicator' defined in class path resource [org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'configServerHealthIndicator' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.config.server.config.CompositeConfiguration': Unsatisfied dependency expressed through method 'setEnvironmentRepos' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository.
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configServerHealthIndicator' defined in class path resource [org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'configServerHealthIndicator' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.config.server.config.CompositeConfiguration': Unsatisfied dependency expressed through method 'setEnvironmentRepos' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configServerHealthIndicator' defined in class path resource [org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'configServerHealthIndicator' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.config.server.config.CompositeConfiguration': Unsatisfied dependency expressed through method 'setEnvironmentRepos' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.config.server.config.CompositeConfiguration': Unsatisfied dependency expressed through method 'setEnvironmentRepos' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository.
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository.
Caused by: java.lang.IllegalStateException: You need to configure a uri for the git repository.
But i have a gitRepo in my bootstrap.yml, and it's working when i use it without Dockerfile:但是我的 bootstrap.yml 中有一个 gitRepo,当我在没有 Dockerfile 的情况下使用它时它正在工作:
spring:
application:
name: CONFIG-SERVER
profiles:
active:
- git
cloud:
config:
server:
git:
default-label: main
uri: https://github.com/hideyourname/cloud-config-server.git
Soo... i think i have a problem with the way i created Dockerfile because it's can find my git even if is there Soo...我认为我创建 Dockerfile 的方式有问题,因为它可以找到我的 git,即使它在那里
FROM openjdk:11 as BUILDER
LABEL maintainer = "petrea config server"
#EXPOSE 8080 SA VEDE MDACA MERGE
COPY /target/boys-config.jar boys-config.jar
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf /boys-config.jar)
#Stage 2
FROM openjdk:11-slim
VOLUME /tmp
ARG DEPENDENCY=/target/dependency
COPY --from=BUILDER ${DEPENDENCY}/BOOT-INF/lib /boys-config/lib
COPY --from=BUILDER ${DEPENDENCY}/META-INF /boys-config/META-INF
COPY --from=BUILDER ${DEPENDENCY}/BOOT-INF/classes /boys-config
#execute the application
ENTRYPOINT ["java", "-cp", "boys-config:boys-config/lib/*", "com.petrea.boys-config-server.BoysConfigServerApplication"]
I have Cloud Config Server dependency in POM, @EnableConfigServer in my main class, but for some reason, when i use Dockerfile for building this image, it's failing... any thoughts please?我在 POM 中有 Cloud Config Server 依赖项,在我的主 class 中有 @EnableConfigServer,但出于某种原因,当我使用 Dockerfile 构建此图像时,它失败了……有什么想法吗?
If you are following the examples in the book referenced above, I will suggest you move the below snippet from bootsrap.yml to applications.yml.如果您按照上面引用的书中的示例进行操作,我建议您将以下代码片段从 bootsrap.yml 移至 applications.yml。
spring:
application:
name: CONFIG-SERVER
profiles:
active:
- git
cloud:
config:
server:
git:
default-label: main
uri: https://github.com/hideyourname/cloud-config-server.git
That's what I did and it worked for me.这就是我所做的,它对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.