Closed aoudiamoncef closed 3 years ago
Optional is a spring boot feature. It doesn't matter if it's consul or not
If I don't have spring-cloud-starter-consul-config
as a dependency I get
14:22:06.907 [main] DEBUG org.springframework.boot.diagnostics.FailureAnalyzers - FailureAnalyzer org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer@2c7b5824 failed
java.lang.NoClassDefFoundError: org/springframework/jdbc/CannotGetJdbcConnectionException
at org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer.analyze(HikariDriverConfigurationFailureAnalyzer.java:29)
at org.springframework.boot.diagnostics.AbstractFailureAnalyzer.analyze(AbstractFailureAnalyzer.java:35)
at org.springframework.boot.diagnostics.FailureAnalyzers.analyze(FailureAnalyzers.java:118)
at org.springframework.boot.diagnostics.FailureAnalyzers.reportException(FailureAnalyzers.java:111)
at org.springframework.boot.SpringApplication.reportFailure(SpringApplication.java:846)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:821)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:336)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.example.democonsul.DemoconsulApplication.main(DemoconsulApplication.java:27)
Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.CannotGetJdbcConnectionException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 10 common frames omitted
14:22:06.909 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Unable to load config data from 'optional:consul:'
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:125)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.resolve(StandardConfigDataLocationResolver.java:112)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.lambda$resolve$1(ConfigDataLocationResolvers.java:114)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:125)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:114)
at org.springframework.boot.context.config.ConfigDataLocationResolvers.resolve(ConfigDataLocationResolvers.java:106)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:101)
at org.springframework.boot.context.config.ConfigDataImporter.resolve(ConfigDataImporter.java:93)
at org.springframework.boot.context.config.ConfigDataImporter.resolveAndLoad(ConfigDataImporter.java:81)
at org.springframework.boot.context.config.ConfigDataEnvironmentContributors.withProcessedImports(ConfigDataEnvironmentContributors.java:119)
at org.springframework.boot.context.config.ConfigDataEnvironment.processInitial(ConfigDataEnvironment.java:230)
at org.springframework.boot.context.config.ConfigDataEnvironment.processAndApply(ConfigDataEnvironment.java:217)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:88)
at org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor.postProcessEnvironment(ConfigDataEnvironmentPostProcessor.java:80)
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:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
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:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
at com.example.democonsul.DemoconsulApplication.main(DemoconsulApplication.java:27)
Caused by: java.lang.IllegalStateException: File extension is not known to any PropertySourceLoader. If the location is meant to reference a directory, it must end in '/'
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferencesForFile(StandardConfigDataLocationResolver.java:200)
at org.springframework.boot.context.config.StandardConfigDataLocationResolver.getReferences(StandardConfigDataLocationResolver.java:122)
... 30 common frames omitted
Otherwise with logging.level.org.springframework.boot.context.config=TRACE
I see
2021-01-11 14:20:50.500 TRACE 214689 --- [ main] .b.c.c.ConfigDataEnvironmentContributors : Processing imports [optional:consul:]
2021-01-11 14:20:50.500 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataLoaders : Loading [ConsulConfigDataResource@4263b080 context = 'config/application/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']] using loader org.springframework.cloud.consul.config.ConsulConfigDataLoader
2021-01-11 14:20:50.500 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataImporter : Ignoring missing config data resource '[ConsulConfigDataResource@4263b080 context = 'config/application/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']]' via location 'optional:consul:'
2021-01-11 14:20:50.500 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataLoaders : Loading [ConsulConfigDataResource@62d363ab context = 'config/application,default/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']] using loader org.springframework.cloud.consul.config.ConsulConfigDataLoader
2021-01-11 14:20:50.500 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataImporter : Ignoring missing config data resource '[ConsulConfigDataResource@62d363ab context = 'config/application,default/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']]' via location 'optional:consul:'
2021-01-11 14:20:50.500 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataLoaders : Loading [ConsulConfigDataResource@3aee3976 context = 'config/testconsul/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']] using loader org.springframework.cloud.consul.config.ConsulConfigDataLoader
2021-01-11 14:20:50.500 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataImporter : Ignoring missing config data resource '[ConsulConfigDataResource@3aee3976 context = 'config/testconsul/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']]' via location 'optional:consul:'
2021-01-11 14:20:50.501 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataLoaders : Loading [ConsulConfigDataResource@27cf3151 context = 'config/testconsul,default/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']] using loader org.springframework.cloud.consul.config.ConsulConfigDataLoader
2021-01-11 14:20:50.501 TRACE 214689 --- [ main] o.s.b.context.config.ConfigDataImporter : Ignoring missing config data resource '[ConsulConfigDataResource@27cf3151 context = 'config/testconsul,default/', optional = true, properties = [ConsulConfigProperties@2af616d3 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@71f67a79 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'testconsul']]' via location 'optional:consul:'
2021-01-11 14:20:50.501 TRACE 214689 --- [ main] .b.c.c.ConfigDataEnvironmentContributors : Nothing imported
Hi @spencergibb,
I have a fully working application in production with:
<spring-boot-bom.version>2.3.8.RELEASE</spring-boot-bom.version>
<spring-cloud-bom.version>Hoxton.SR9</spring-cloud-bom.version>
...
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
I tried to upgrade and got this issue and others which I resoled.
There is a new release of Spring Boot with a bunch of bugfixes, I'll give it a try.
Thanks
I migrated my config properties based on breaking changes and this article
I get the following with optional
2021-01-27 14:37:05.482 TRACE 197399 --- [ main] o.s.b.context.config.ConfigDataLoaders : Loading [ConsulConfigDataResource@55cb6996 context = '/config/appname_test/', optional = true, properties = [ConsulConfigProperties@1807e3f6 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@480d3575 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'demo']] using loader org.springframework.cloud.consul.config.ConsulConfigDataLoader
2021-01-27 14:37:05.482 TRACE 197399 --- [ main] o.s.b.context.config.ConfigDataImporter : Ignoring missing config data resource '[ConsulConfigDataResource@55cb6996 context = '/config/appname_test/', optional = true, properties = [ConsulConfigProperties@1807e3f6 enabled = true, prefix = 'config', defaultContext = 'application', profileSeparator = ',', format = KEY_VALUE, dataKey = 'data', aclToken = [null], watch = [ConsulConfigProperties.Watch@480d3575 waitTime = 55, enabled = true, delay = 1000], failFast = true, name = 'demo']]' via location 'optional:consul:localhost:8500/config/appname_test'
This may have been fixed with #693
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Sorry but I met the same situation with Spring Boot 2.4.4 and Spring Cloud 2020.0.2 My application.yml:
spring:
application:
name:
my-app-name
cloud:
consul:
config:
format: yaml
and I started with JAVA_OPTS='-Dspring.config.import=consul: -Dspring.cloud.consul.host=MY_CONSUL_IP_HERE'
Hi, for someone facing this issue on latest spring boot 2.6.5 fixed adding the following two dependencies.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
Hi,
I tried to add
optional:
prefix then I got:application.yml:
Thanks