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

Error during startup #722

Closed hendisantika closed 1 year ago

hendisantika commented 3 years ago

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

spencergibb commented 3 years ago

You should either remove bootstrap or remove spring.config.import

spring-cloud-issues commented 3 years ago

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.

hendisantika commented 3 years ago

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.

spencergibb commented 3 years ago

You get the same error by doing both things?

hendisantika commented 3 years ago

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

rodrigorodrigues commented 2 years ago

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
chenzhiguo commented 2 years ago

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
chenzhiguo commented 2 years ago

Where are the configDataConsulConfigIndexes come from? I think it from spring-cloud-starter-bootstrap, is not it?

chenzhiguo commented 2 years ago

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.

spencergibb commented 2 years ago

spring.config.import should not go in bootstrap.yml

zhnkc9 commented 2 years ago

why?

spencergibb commented 1 year ago

@zhnkc9 because bootstrap automatically imports configuration without the need for spring.config.import