0

我正在探索 Consul 的发现和配置服务器。我已经添加了所需的依赖项并设置了 yml 文件。当我尝试使用spring cloud cli(Spring run)启动服务器时,我收到以下错误,我无法解决。任何帮助表示赞赏。

错误:“组件需要一个名为 'configServerRetryInterceptor' 的 bean,但无法找到。”

我试图定义这个bean,但是当我通过spring cloud cli启动应用程序时,它无法识别它。

请看下面的代码

App.groovy

@Grab("spring-cloud-starter-consul-config")
@Grab("spring-cloud-starter-consul-discovery")

@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
@Log
class Application{

@Autowired
Greeter greeter

int counter = 0

@RequestMapping(value = "/counter", produces = "application/json")
String produce() {
    counter++
    log.info("Produced a value: ${counter}")

    "{\"value\": ${counter}}"
}

@RequestMapping("/")
String home() {
    "${greeter.greeting} World!"
}

@RequestMapping(value = '/questions/{questionId}')
@HystrixCommand(fallbackMethod = "defaultQuestion")
def question(@PathVariable String questionId) {
    if(Math.random() < 0.5) {
        throw new RuntimeException('random');
    }
    [questionId: questionId]
}

def defaultQuestion(String questionId) {
   [questionId: 'defaultQuestion']
}

}

@Component
@RefreshScope
class Greeter {
@Value('${greeting}')
String greeting
}

bootstrap.yml

consul:
  host: localhost
  port: 8500
  config:
    enabled: true
    prefix: config
    defaultContext: master
    profileSeparator: '::'
    format: FILES
  discovery:
    instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
    health-check-url: http://127.0.0.1:${server.port}/health
4

1 回答 1

1

此问题是由于提取了不需要的依赖项。显式禁用 spring 云配置和 spring 云发现修复了它。

spring:
  cloud:
    config:
      enabled: false
      discovery:
        enabled: false
        serviceId: CONFIG
eureka:
  client:
    register-with-eureka: false
    fetch-registry: false
于 2017-02-25T14:09:52.000 回答