spring-cloud-consul icon indicating copy to clipboard operation
spring-cloud-consul copied to clipboard

Error during startup

Open hendisantika opened this issue 3 years ago • 11 comments

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

hendisantika avatar May 12 '21 08:05 hendisantika

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

spencergibb avatar Jun 03 '21 18:06 spencergibb

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.

spring-cloud-issues avatar Jun 10 '21 18:06 spring-cloud-issues

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.

hendisantika avatar Jun 10 '21 23:06 hendisantika

You get the same error by doing both things?

spencergibb avatar Jun 10 '21 23:06 spencergibb

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

hendisantika avatar Jun 11 '21 00:06 hendisantika

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

rodrigorodrigues avatar Dec 12 '21 00:12 rodrigorodrigues

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 avatar Dec 16 '21 05:12 chenzhiguo

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

chenzhiguo avatar Dec 16 '21 05:12 chenzhiguo

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.

chenzhiguo avatar Dec 16 '21 06:12 chenzhiguo

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

spencergibb avatar Dec 16 '21 06:12 spencergibb

why?

zhnkc9 avatar Aug 24 '22 03:08 zhnkc9

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

spencergibb avatar Mar 08 '23 22:03 spencergibb