简体   繁体   中英

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:

    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:

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

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM