spring-cloud / spring-cloud/spring-cloud-consul

Error getting config from consul if two profiles specified with different values of some properties

Open
#802 14 comments 0 reactions 1 assignee View on GitHub

@spencergibb is already working on this.

Since Jun 30, 2023.

in progress
Dominant language
Java
Stars
822
Forks
539
Avg merge
9h 31m
Merged PRs (30d)
7

Description

I've updated spring cloud from 2021.0.4 to 2021.0.5.
After updating I get an error while starting my spring-boot application.
I noticed, that problem is because I have test profile with disabled cloud services.
If I comment all properties which has **.discovery.** in name - it works
Of course it doesn't work in 'test' profile, because by default, discovery is enabled.

As I understand, such behaviour happens because of https://github.com/spring-cloud/spring-cloud-consul/issues/785
Is that bug? Or I have mistakes in my configuration?

my application.yml

server:
  port: 8100

spring:
  application:
    name: rabbitmq-client
  config:
    import: "configserver:,consul:"

  cloud:
    stream:
      bindings:
        test:
          destination: data_broker
          group: client1_group
        process-in-0:
          destination: data_broker
          group: client_group
    consul:
      config:
        enabled: true
        format: YAML
        prefixes: config
        default-context: rabbitmq-client
        data-key: data
        profile-separator: '::'
        name: rabbitmq-client
      discovery:
        instance-id: ${spring.application.name}
        prefer-ip-address: true
        metadata:
          version: 1.0
      host: ${CLOUD_SERVICES_ADDR}
      port: 8500

    config:
      enabled: true
      discovery:
        enabled: true
        service-id: config-service

  rabbitmq:
    host: ${CLOUD_SERVICES_ADDR}
    port: 5672
    username: ${RABBITMQ_USER:}
    password: ${RABBITMQ_PASSWORD:}


---
spring:
  config:
    activate:
      on-profile: test

  cloud:
    consul:
      discovery:
        enabled: false
      enabled: false
      config:
        enabled: false
    discovery:
      enabled: false
    config:
      enabled: false
      discovery:
        enabled: false

Stacktrace:

02:21:30.899 [restartedMain] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
org.springframework.boot.context.config.ConfigDataResourceNotFoundException: Config data resource '[ConsulConfigDataResource@651d884b context = 'config/rabbitmq-client::default/', optional = true, properties = [ConsulConfigProperties@27342471 enabled = true, prefixes = list['config'], defaultContext = 'rabbitmq-client', profileSeparator = '::', format = YAML, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@59f16715 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'rabbitmq-client'], profile = 'default']' via location 'consul:' cannot be found
	at org.springframework.boot.context.config.ConfigDataResourceNotFoundException.withLocation(ConfigDataResourceNotFoundException.java:97)
	at org.springframework.boot.context.config.ConfigDataImporter.handle(ConfigDataImporter.java:145)
	at org.springframework.boot.context.config.ConfigDataImporter.load(ConfigDataImporter.java:136)
	at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:86)
	at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:116)
	at org.springframework.boot.context.config.ConfigDataEnvironment.processWithProfiles(ConfigDataEnvironment.java:311)
	at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:232)
	at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:102)
	at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:94)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:102)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:87)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:343)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
	at ua.com.timur.rabbitmqclient.RabbitmqClientApplication.main(RabbitmqClientApplication.java:12)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.cloud.config.discovery.enabled' to java.lang.Boolean
	at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:387)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:347)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:332)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:262)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:223)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:210)
	at org.springframework.cloud.consul.discovery.configclient.ConsulConfigServerBootstrapper.isDiscoveryEnabled(ConsulConfigServerBootstrapper.java:102)
	at org.springframework.cloud.consul.discovery.configclient.ConsulConfigServerBootstrapper.lambda$initialize$1(ConsulConfigServerBootstrapper.java:58)
	at org.springframework.boot.DefaultBootstrapContext.getInstance(DefaultBootstrapContext.java:119)
	at org.springframework.boot.DefaultBootstrapContext.getOrElseThrow(DefaultBootstrapContext.java:111)
	at org.springframework.boot.DefaultBootstrapContext.get(DefaultBootstrapContext.java:88)
	at org.springframework.cloud.consul.config.ConsulConfigDataLoader.getBean(ConsulConfigDataLoader.java:103)
	at org.springframework.cloud.consul.config.ConsulConfigDataLoader.doLoad(ConsulConfigDataLoader.java:62)
	at org.springframework.cloud.consul.config.ConsulRetryBootstrapper.lambda$null$2(ConsulRetryBootstrapper.java:61)
	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329)
	at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:209)
	at org.springframework.cloud.consul.config.ConsulRetryBootstrapper.lambda$null$3(ConsulRetryBootstrapper.java:60)
	at org.springframework.cloud.consul.config.ConsulConfigDataLoader.load(ConsulConfigDataLoader.java:54)
	at org.springframework.cloud.consul.config.ConsulConfigDataLoader.load(ConsulConfigDataLoader.java:38)
	at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:107)
	at org.springframework.boot.context.config.ConfigDataImporter.load(ConfigDataImporter.java:128)
	... 28 common frames omitted
Caused by: org.springframework.boot.context.config.InactiveConfigDataAccessException: Inactive property source 'Config resource 'class path resource [application.yml]' via location 'optional:classpath:/' (document #1)' imported from location 'class path resource [application.yml]' cannot contain property 'spring.cloud.config.discovery.enabled' [origin: class path resource [application.yml] - 72:18]
	at org.springframework.boot.context.config.InactiveConfigDataAccessException.throwIfPropertyFound(InactiveConfigDataAccessException.java:126)
	at org.springframework.boot.context.config.ConfigDataEnvironmentContributors$InactiveSourceChecker.onSuccess(ConfigDataEnvironmentContributors.java:310)
	at org.springframework.boot.context.properties.bind.Binder.handleBindResult(Binder.java:354)
	at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:344)
	... 47 common frames omitted
02:21:30.899 [restartedMain] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

Config data resource '[ConsulConfigDataResource@651d884b context = 'config/rabbitmq-client::default/', optional = true, properties = [ConsulConfigProperties@27342471 enabled = true, prefixes = list['config'], defaultContext = 'rabbitmq-client', profileSeparator = '::', format = YAML, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@59f16715 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'rabbitmq-client'], profile = 'default']' via location 'consul:' does not exist

Action:

Check that the value 'consul:' at class path resource [application.yml] - 10:13 is correct, or prefix it with 'optional:'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.