我正在探索 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