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

ConfigDataResourceNotFoundException not handled #693

Closed aoudiamoncef closed 3 years ago

aoudiamoncef commented 3 years ago

Hi,

application.yml:

spring:
  config:
    import: "consul:${spring.cloud.consul.host}:${spring.cloud.consul.port}/dev"

Consul:

curl -XPUT --data-binary @application.yml http://127.0.0.1:8500/v1/kv/my-api/dev.yml

At startup, I got:

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

Description:

Config data resource '[ConsulConfigDataResource@714e7fd5 context = '/dev.properties', optional = false, properties = [ConsulConfigProperties@38fe6b0d enabled = true, prefix = 'my-api', defaultContext = 'application', profileSeparator = ',', format = FILES, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@6c3fd532 waitTime = 55, enabled = false, delay = 1000], failFast = true, name = 'adp-api-s']]' via location 'consul:localhost:8500/dev' does not exist

Action:

Check that the value 'consul:localhost:8500/dev' at class path resource [application.yaml] - 96:13 is correct, or prefix it with 'optional:'

Workaround:

curl -XPUT --data-binary @application.yml http://127.0.0.1:8500/v1/kv/my-api/dev.yml
curl -XPUT --data-binary @application.yaml http://127.0.0.1:8500/v1/kv/my-api/dev.yaml
curl -XPUT --data-binary @application.properties http://127.0.0.1:8500/v1/kv/my-api/dev.properties

I tried another configuration without success:

  config:
    import: "optional:consul:${spring.cloud.consul.host}:${spring.cloud.consul.port}/dev"
    on-not-found: ignore

Related to issue #692

Thanks

spencergibb commented 3 years ago

See https://github.com/spring-cloud/spring-cloud-consul/issues/692#issuecomment-758168908

Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

aoudiamoncef commented 3 years ago

Hi @spencergibb, I'll try to reproduce the issue ASAP on a small project.

fkohantorabi commented 3 years ago

HI @spencergibb

I am having a similar problem and I've reproduced what @aoudiamoncef is describing in https://github.com/fkohantorabi/ConsulBugReport300. Please take a look. Feel free to play around with spring.config.import since there are multiple scenarios you can end up with.

spencergibb commented 3 years ago

@fkohantorabi so your reproducer doesn't have the same exception as reported.

java.lang.IllegalArgumentException: Source must not be null
    at org.springframework.util.Assert.notNull(Assert.java:201)
    at org.springframework.boot.context.properties.source.SpringConfigurationPropertySource.from(SpringConfigurationPropertySource.java:145)
    at org.springframework.boot.context.properties.source.ConfigurationPropertySource.from(ConfigurationPropertySource.java:96)
    at org.springframework.boot.context.config.ConfigDataEnvironmentContributor.ofUnboundImport(ConfigDataEnvironmentContributor.java:313)
    at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.lambda$asContributors$1(ConfigDataEnvironmentContributors.java:172)
    at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
    at java.base/java.util.Collections$UnmodifiableMap.forEach(Collections.java:1505)
    at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.asContributors(ConfigDataEnvironmentContributors.java:163)
    at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:123)
    at org.springframework.boot.context.config.ConfigDataEnvironment.processWithProfiles(ConfigDataEnvironment.java:305)
    at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:230)
    at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:97)
    at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:89)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
    at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
    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:82)
    at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
    at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:362)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1311)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1300)
    at com.spring.bugreport.ConsulBug.ConsulBugApplication.main(ConsulBugApplication.java:10)
fkohantorabi commented 3 years ago

@spencergibb the exception you posted is what you get If you have spring.config.import=optional:consul:/dev. If you change it to spring.config.import=consul:/dev you will see the error @aoudiamoncef has reported. Apologies for the confusion.