2

Jhipster Registry 页面上,提到我们可以通过以下参数为 Spring Cloud Config 设置 Git 存储库。

--spring.profiles.active=prod --spring.security.user.password=admin --jhipster.security.authentication.jwt.secret=secret-key --spring.cloud.config.server.composite=https://github.com/jhipster/jhipster-registry-sample-config --spring.cloud.config.server.composite[0].type=git --spring.cloud.config.server.composite[0].uri=https://github.com/jhipster/jhipster-registry-sample-config

但是我想通过 docker-compose 中的环境变量设置这些参数,我该如何实现呢?特别是这个: spring.cloud.config.server.composite[0].uri 带方括号。

更新

我尝试了 Gaël Marziou 的答案中定义的拼写,但没有奏效。这是我正在使用的 docker jhipster-registry.yml,由 jhipster docker-compose subgenerator 生成,我在其中添加了 Spring Cloud Config

version: '2'
services:
    jhipster-registry:
        image: jhipster/jhipster-registry
        environment:
        - SPRING_PROFILES_ACTIVE=prod,git
        - SPRING_SECURITY_USER_PASSWORD=admin
        - JHIPSTER_REGISTRY_PASSWORD=admin
        - JHIPSTER_LOGGING_LOGSTASH_ENABLED=true
        - JHIPSTER_LOGGING_LOGSTASH_HOST=jhipster-logstash
        - JHIPSTER_METRICS_LOGS_ENABLED=true
        - JHIPSTER_METRICS_LOGS_REPORTFREQUENCY=60
        - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE=https://github.com/anthonyrichir/demo-feign-config
        - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
        - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/anthonyrichir/demo-feign-config
        ports:
        - 8761:8761

使用此配置,注册表说:

Failed to bind properties under 'spring.cloud.config.server.composite' to java.util.List<java.util.Map<java.lang.String, java.lang.Object>>:

    Reason: No converter found capable of converting from type [java.lang.String] to type [java.util.List<java.util.Map<java.lang.String, java.lang.Object>>]

我也试过这个配置:

version: '2'
services:
    jhipster-registry:
        image: jhipster/jhipster-registry
        environment:
        - SPRING_PROFILES_ACTIVE=prod,git
        - SPRING_SECURITY_USER_PASSWORD=admin
        - JHIPSTER_REGISTRY_PASSWORD=admin
        - JHIPSTER_LOGGING_LOGSTASH_ENABLED=true
        - JHIPSTER_LOGGING_LOGSTASH_HOST=jhipster-logstash
        - JHIPSTER_METRICS_LOGS_ENABLED=true
        - JHIPSTER_METRICS_LOGS_REPORTFREQUENCY=60
        - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_TYPE=git
        - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI=https://github.com/anthonyrichir/demo-feign-config
        ports:
        - 8761:8761

我收到此错误:

Caused by: java.lang.IllegalStateException: You need to configure a uri for the git repository
    at org.springframework.util.Assert.state(Assert.java:73)
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.afterPropertiesSet(JGitEnvironmentRepository.java:245)
    at org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository.afterPropertiesSet(MultipleJGitEnvironmentRepository.java:69)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1767)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1704)
    ... 88 common frames omitted
4

1 回答 1

1

spring.cloud.config.server.composite[0].uri属性应该映射到SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_URI环境变量。

请参阅https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-relaxed-binding

于 2018-08-16T21:02:29.870 回答