【问题标题】:Issues in resolving placeholders in bootstrap.properties after upgrading to Springboot 2升级到 Springboot 2 后解决 bootstrap.properties 中占位符的问题
【发布时间】:2018-03-09 14:55:58
【问题描述】:

弹簧依赖:

     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

Spring-cloud 依赖:

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.M8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

启动时出错 -

2018-03-09 19:41:35.096  WARN 97916 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'propertySourceBootstrapConfiguration': Unsatisfied dependency expressed through field 'propertySourceLocators'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configServicePropertySource' defined in org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration: Unsatisfied dependency expressed through method 'configServicePropertySource' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'configClientProperties': Could not bind properties to 'ConfigClientProperties' : prefix=spring.cloud.config, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.config.password' to java.lang.String

bootstrap.properties:

spring.cloud.config.failFast=true
spring.profiles.active=${ACTIVE_PROFILES:dev}
spring.cloud.config.uri=${CLOUD_CONFIG_URL:http://domainname/cloud-config}
spring.cloud.config.username=${CLOUD_CONFIG_USERNAME}
spring.cloud.config.password=${CLOUD_CONFIG_PASSWORD}

【问题讨论】:

    标签: spring-boot spring-cloud-config spring2.x


    【解决方案1】:

    想通了:

    spring.cloud.config.username=${CLOUD_CONFIG_USERNAME}
    spring.cloud.config.password=${CLOUD_CONFIG_PASSWORD}
    

    需要改成-

    spring.cloud.config.username=${CLOUD_CONFIG_USERNAME:}
    spring.cloud.config.password=${CLOUD_CONFIG_PASSWORD:}
    

    注意末尾的冒号。不过,这曾经在更早的时候起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-25
      • 2021-08-25
      • 1970-01-01
      • 2018-05-29
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多