spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
813 stars 541 forks source link

2.0.0.M6 and Spring Boot 2.0.0.RELEASE compatibility #405

Closed mveitas closed 6 years ago

mveitas commented 6 years ago

I recently tried to update to using Spring Boot 2.0.0.RELEASE along with spring-cloud-consul:2.0.0.M6.

When starting the app I get the following:

2018-03-06 18:09:38,387 WARN  [main]   o.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 'consulPropertySourceLocator' defined in org.springframework.cloud.consul.config.ConsulConfigBootstrapConfiguration$ConsulPropertySourceConfiguration: Unsatisfied dependency expressed through method 'consulPropertySourceLocator' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'consulConfigProperties': Could not bind properties to 'ConsulConfigProperties' : prefix=spring.cloud.consul.config, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.consul.config' to org.springframework.cloud.consul.config.ConsulConfigProperties

This is the contents of the bootstrap.yaml that we are using:

spring:
  application:
    name: search-api
    profile: ${APPENV:local}
    version: ${SVCVERSION:1.0}
  cloud:
    consul:
      host: ${CONSUL_HOST:localhost}
      port: ${CONSUL_PORT:8500}
      config:
        enabled: ${ENABLE_CONSUL:false}
        format: ${CONSUL_DATA_FORMAT:YAML}
        data-key: ${CONSUL_DATA_KEY:data}
        prefix: config/${spring.application.profile}
        defaultContext: ${spring.application.name}/${spring.application.version}

Below is the maven dep tree for reference:

[INFO] com.everbridge.search-api:jar:0.0.0.1-SNAPSHOT
[INFO] +- ch.hsr:geohash:jar:1.3.0:compile
[INFO] +- ch.qos.logback:logback-access:jar:1.1.8:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.8:compile
[INFO] +- ch.qos.logback:logback-core:jar:1.1.8:compile
[INFO] +- com.everbridge.contact:contact-model:jar:0.0.0.1-SNAPSHOT:compile
[INFO] |  +- javax.el:javax.el-api:jar:3.0.0:compile
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] |  +- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] |  \- org.hibernate:hibernate-validator:jar:5.4.0.Final:compile
[INFO] |     +- javax.validation:validation-api:jar:2.0.0.Final:compile
[INFO] |     \- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.1:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-core:jar:2.9.1:compile
[INFO] +- com.google.code.gson:gson:jar:2.8.2:compile
[INFO] +- de.grundid.opendatalab:geojson-jackson:jar:1.8:compile
[INFO] +- com.google.guava:guava:jar:23.0:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO] |  +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile
[INFO] +- com.vividsolutions:jts:jar:1.13:compile
[INFO] +- io.springfox:springfox-swagger2:jar:2.6.1:compile
[INFO] |  +- io.swagger:swagger-models:jar:1.5.10:compile
[INFO] |  +- io.springfox:springfox-spi:jar:2.6.1:compile
[INFO] |  |  \- io.springfox:springfox-core:jar:2.6.1:compile
[INFO] |  +- io.springfox:springfox-schema:jar:2.6.1:compile
[INFO] |  +- io.springfox:springfox-swagger-common:jar:2.6.1:compile
[INFO] |  +- io.springfox:springfox-spring-web:jar:2.6.1:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.1:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-context:jar:5.0.3.RELEASE:compile
[INFO] |  +- org.springframework.plugin:spring-plugin-metadata:jar:1.2.0.RELEASE:compile
[INFO] |  \- org.mapstruct:mapstruct:jar:1.0.0.Final:compile
[INFO] +- io.springfox:springfox-swagger-ui:jar:2.6.1:compile
[INFO] +- io.swagger:swagger-annotations:jar:1.5.0:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.8.10:compile
[INFO] +- org.elasticsearch.client:elasticsearch-rest-client:jar:6.1.1:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] |  +- org.apache.httpcomponents:httpasyncclient:jar:4.1.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore-nio:jar:4.4.5:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:6.1.1:compile
[INFO] |  +- org.elasticsearch:elasticsearch:jar:6.1.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-core:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-analyzers-common:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-backward-codecs:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-grouping:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-highlighter:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-join:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-memory:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-misc:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-queries:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-queryparser:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-sandbox:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial-extras:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-spatial3d:jar:7.1.0:compile
[INFO] |  |  +- org.apache.lucene:lucene-suggest:jar:7.1.0:compile
[INFO] |  |  +- org.elasticsearch:securesm:jar:1.2:compile
[INFO] |  |  +- org.elasticsearch:elasticsearch-cli:jar:6.1.1:compile
[INFO] |  |  |  \- net.sf.jopt-simple:jopt-simple:jar:5.0.2:compile
[INFO] |  |  +- com.carrotsearch:hppc:jar:0.7.1:compile
[INFO] |  |  +- joda-time:joda-time:jar:2.9.5:compile
[INFO] |  |  +- org.yaml:snakeyaml:jar:1.17:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.8.10:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.10:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.10:compile
[INFO] |  |  +- com.tdunning:t-digest:jar:3.0:compile
[INFO] |  |  +- org.hdrhistogram:HdrHistogram:jar:2.1.9:compile
[INFO] |  |  +- org.apache.logging.log4j:log4j-api:jar:2.9.1:compile
[INFO] |  |  \- org.elasticsearch:jna:jar:4.4.0-1:compile
[INFO] |  +- org.elasticsearch.plugin:parent-join-client:jar:6.1.1:compile
[INFO] |  \- org.elasticsearch.plugin:aggs-matrix-stats-client:jar:6.1.1:compile
[INFO] +- org.locationtech.spatial4j:spatial4j:jar:0.6:compile
[INFO] +- org.projectlombok:lombok:jar:1.16.18:compile (optional) 
[INFO] +- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] +- org.springframework:spring-aop:jar:5.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-core:jar:5.0.3.RELEASE:compile
[INFO] |     \- org.springframework:spring-jcl:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:5.0.3.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.0.RELEASE:compile
[INFO] |  \- org.springframework.boot:spring-boot:jar:2.0.0.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.0.RELEASE:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  \- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-actuator:jar:2.0.0.RELEASE:compile
[INFO] |  |  \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.4:compile
[INFO] |  \- io.micrometer:micrometer-core:jar:1.0.1:compile
[INFO] |     \- org.latencyutils:LatencyUtils:jar:2.0.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.4:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.4:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.0.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.28:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.28:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.28:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.7.Final:compile
[INFO] |  +- org.springframework:spring-web:jar:5.0.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.0.4.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.0.4.RELEASE:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-consul-config:jar:2.0.0.M6:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-consul:jar:2.0.0.M6:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-commons:jar:2.0.0.M7:compile
[INFO] |  |  |  \- org.springframework.security:spring-security-crypto:jar:5.0.2.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-context:jar:2.0.0.M7:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-consul-core:jar:2.0.0.M6:compile
[INFO] |  |  \- com.ecwid.consul:consul-api:jar:1.3.0:compile
[INFO] |  \- org.springframework.cloud:spring-cloud-consul-config:jar:2.0.0.M6:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.assertj:assertj-core:jar:3.8.0:test
[INFO] \- org.mockito:mockito-core:jar:2.13.0:test
[INFO]    +- net.bytebuddy:byte-buddy:jar:1.7.9:test
[INFO]    +- net.bytebuddy:byte-buddy-agent:jar:1.7.9:test
[INFO]    \- org.objenesis:objenesis:jar:2.6:test
spencergibb commented 6 years ago

Thanks for the details, but it's not enough to diagnose the problem. Can you provide a complete, minimal, verifiable sample that reproduces the problem?

mveitas commented 6 years ago

Sure I'll spin up a sample repo that can reproduce this

mveitas commented 6 years ago

I narrowed down the issue to an older version of hibernate-validator being pulled into our app. The exception being thrown at app startup doesn't surface the cause and after some debugging found the real reason: javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotEmpty' validating type 'java.lang.String'. Check configuration for 'defaultContext'

This would explain why things started to break after 2.0.0.M5 when this change was made: https://github.com/spring-cloud/spring-cloud-consul/commit/01e93da27e9e2756206782f998ea18b387458065

spencergibb commented 5 years ago

Did you read the comment above? https://github.com/spring-cloud/spring-cloud-consul/issues/405#issuecomment-371132420

sarbajitdutta commented 5 years ago

I am having a similar issue where I am trying to start spring cloud aws with secrets manager and I get the same error.

Pom.xml

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.5.RELEASE</version>
            <type>pom</type>
        </dependency>
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-aws-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-aws-autoconfigure</artifactId>
         </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-aws-secrets-manager-config -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.2.4.Final</version>
        </dependency>


Failed to bind properties under 'aws.secretsmanager' to org.springframework.cloud.aws.secretsmanager.AwsSecretsManagerProperties:

    Reason: HV000030: No validator could be found for constraint 'javax.validation.constraints.NotEmpty' validating type 'java.lang.String'. Check configuration for 'defaultContext'

Action:

Update your application's configuration
spencergibb commented 5 years ago

@sarbajitdutta your app doesn't include spring-cloud-consul.

If you can provide a complete, minimal, verifiable sample that reproduces the problem, please open an issue in spring-cloud-aws. It should be available as a GitHub (or similar) project or attached to this issue as a zip file.