spring-cloud-consul
spring-cloud-consul copied to clipboard
Error during startup
Hi All, I am using Spring Cloud 2020.0.2 with Consul.
I am having error during startup as follow:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method configWatch in org.springframework.cloud.consul.config.ConsulConfigAutoConfiguration$ConsulRefreshConfiguration required a single bean, but 2 were found:
- consulPropertySourceLocator: defined by method 'consulPropertySourceLocator' in class path resource [org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration$ConsulPropertySourceConfiguration.class]
- configDataConsulConfigIndexes: a programmatically registered singleton
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
> Task :bootRun FAILED
:bootRun (Thread[Execution worker for ':' Thread 2,5,main]) completed. Took 4 mins 1.74 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command '/Users/hendisantika/.sdkman/candidates/java/11.0.9.j9-adpt/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 6m 41s
5 actionable tasks: 5 executed
Some of the file system contents retained in the virtual file system are on file systems that Gradle doesn't support watching. The relevant state was discarded to ensure changes to these locations are properly detected. You can override this by explicitly enabling file system watching.
Watched directory hierarchies: [/Users/hendisantika/IdeaProjects/docker-spring-cloud/Catalog-Service]
You can try my repo to run on your local --> https://gitlab.com/microservice-samples/docker-spring-cloud
Any idea?
Thanks
You should either remove bootstrap or remove spring.config.import
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.
You mean remove this properties spring.config.import="consul:localhost:8500;catalog"
or remove org.springframework.cloud:spring-cloud-starter-bootstrap
lib?
If that is. I already commented it but the error still exist.
You get the same error by doing both things?
Another error actually:
Now I've got:
com.ecwid.consul.transport.TransportException: java.net.UnknownHostException: consul: nodename nor servname provided, or not known
But, My Consul Server already run
Hi just to let you know if somebody still facing this issue, I tried a few combinations and the only one that worked was excluding ConsulConfigAutoConfiguration
, the final yml looks like this.
---
spring:
config:
activate:
on-profile: consul
import: consul:${consul_url:localhost:8500}
cloud:
consul:
config:
fail-fast: ${FAIL_FAST:true}
format: yaml #Only in the case if you have yml config to bind
autoconfigure:
exclude: org.springframework.cloud.consul.config.ConsulConfigAutoConfiguration
I have encountered the same mistake.
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method configWatch in org.springframework.cloud.consul.config.ConsulConfigAutoConfiguration$ConsulRefreshConfiguration required a single bean, but 2 were found:
- consulPropertySourceLocator: defined by method 'consulPropertySourceLocator' in class path resource [org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration$ConsulPropertySourceConfiguration.class]
- configDataConsulConfigIndexes: a programmatically registered singleton
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
Where are the configDataConsulConfigIndexes
come from? I think it from spring-cloud-starter-bootstrap
, is not it?
The reason for this problem should be referenced to spring-cloud-starter-bootstrap
, but it defines spring.config.import
in non-bootstrap.yml. We should remove spring-cloud-starter-bootstrap
dependency or remove spring.config.import
in application-xx.yml
.
spring.config.import should not go in bootstrap.yml
why?
@zhnkc9 because bootstrap automatically imports configuration without the need for spring.config.import