我在使用Consul来实现配置中心的时候遇到的一个问题,记录一下。
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-23 14:42:12.062 ERROR 43452 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method configWatch in org.springframework.cloud.consul.config.ConsulConfigAutoConfiguration$ConsulRefreshConfiguration required a single bean, but 2 were found:
- configDataConsulConfigProperties: a programmatically registered singleton - consulConfigProperties: defined by method 'consulConfigProperties' in class path resource [org/springframework/cloud/consul/config/ConsulConfigBootstrapConfiguration$ConsulPropertySourceConfiguration.class]
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
Disconnected from the target VM, address: '127.0.0.1:58460', transport: 'socket'
Process finished with exit code 1
我在项目中引入了bootstrap以及加入了
spring:
config:
import: optional:consul:localhost:8500
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
解决方案:
要么去掉bootstrap的包,要么删掉import:optional:consul:...