我正在探索领域的发现和配置服务器。我添加了所需的依赖项并设置了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
答案 0 :(得分:1)
此问题是由于不必要的依赖项被拉出来的。 明确禁用spring cloud配置和spring spring discovery修复了它。
spring:
cloud:
config:
enabled: false
discovery:
enabled: false
serviceId: CONFIG
eureka:
client:
register-with-eureka: false
fetch-registry: false