Iam使用spring-cloud-config进行集中配置和领事进行服务发现。像尤里卡第一引导程序 - 春支持领事第一引导,即启动客户端服务 - 我应该通过领事查找配置服务器。另一方面工作完全正常,即 - 在配置客户端bootstrap.properties - 我提供spring.cloud.config.uri
= http://localhost:8888它位于配置服务器并从它拉配置。而在我的客户端应用程序的配置库 - 我提供领事配置,如:领事第一bootstrap与春天云配置
spring.cloud.consul.host=localhost ,
spring.cloud.consul.port=8500
但是,当我尝试使用领事首先引导我无法读取配置服务器的属性。
客户端应用程序(用于领事第一自举):
pom.xml
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<!-- <version>Brixton.BUILD-SNAPSHOT</version> -->
<version>Brixton.M5</version>
<relativePath />
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
</dependencies>
bootstrap.properties:
spring.application.name=demo
spring.cloud.config.failFast=true
spring.cloud.config.retry.maxAttempts=20
spring.cloud.config.retry.initialInterval=3000
spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
DemoApplication.java
@EnableDiscoveryClient
@EnableZuulProxy
@SpringBootApplication
public class DemoSleuthApplication {
public static void main(String[] args) {
SpringApplication.run(DemoSleuthApplication.class, args);
}
}
@RefreshScope
@RestController
class RestAPIController
{
@Value(value = "${server.port}")
String port;
@Value(value = "${message}")
String message;
@RequestMapping("/message")
public String welcome(){
String s = this.restTemplate.getForObject("http://localhost:"+this.port+"/message", String.class);
return this.message + s;
}
}
在领事ķ/ V存储 夹结构配置/演示 关键/值:spring.cloud.config.uri=http://localhost:8888
配置服务器混帐回购协议:不添加配置服务器代码简洁 demo.properties
server.port=9080
message=test
理想的情况下,当我执行领事首先引导的概念 - 我想领事应启动和客户端应该使用@EnableDiscoveryClien
t注释和consul属性来标识自身 - 找到配置服务器url,并从服务器配置中获取配置属性。但在我的情况下,服务正在发现和注册领事,但我无法从配置服务器git回购的属性。