Iamは、集中型コンフィギュレーションでspring-cloud-configを使用し、サービスディスカバリーでconsulを使用します。ユーレカの最初のブートストラップのように - 最初のブートストラップ、すなわちクライアントサービスの起動時にスプリングをサポートしますか?私はコンサルでコンフィギュレーションサーバを調べるべきです。つまり、設定クライアントのbootstrap.properties - 私はspring.cloud.config.uri
= http://localhost:8888を提供し、そこからconfigサーバを探し、そこからconfigを取得します。そして、私のクライアントアプリケーションの設定リポジトリに - 私のような領事の設定を提供します。コンサル最初のブートストラップとスプリングクラウドの設定
spring.cloud.consul.host=localhost ,
spring.cloud.consul.port=8500
しかし、私はコンフィグサーバからプロパティを読み取ることができません領事最初のブートストラップを使用しようとします。
クライアントアプリケーション(領事するための第1のブートストラップ):
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:領事K/Vストア フォルダで
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;
}
}
構造体の設定/デモ キー/値:spring.cloud.config.uri=http://localhost:8888
コンフィグサーバGitのレポ:簡潔にするためのconfigサーバーのコードを追加していない demo.properties
server.port=9080
message=test
私は領事最初のブートストラップの概念を実装する理想的
- 私は領事が開始されなければならない考えていますし、クライアント@EnableDiscoveryClien
注釈とconsulプロパティー(config server urlを検索し、サーバー設定からconfigプロパティーを取得する)を使用して自身を識別する必要があります。しかし私のケースでは、サービスが発見され、領事に登録されていますが、私はconfigサーバーgit repoからプロパティを読み取ることができません。