ユーレカの記事[3]サービスディスカバリ(4)

注意:この知識は、フォーカスではありません。

サブモジュールを確認します。microservicecloud-プロバイダDEPT-8001

1.変更DeptController

@Autowired
 プライベートorg.springframework.cloud.client.discovery.DiscoveryClientクライアント。

(値@RequestMapping = "/発見"、メソッド= RequestMethod.GET)
 パブリックオブジェクト・ディスカバリー(){ 
    リストの<string>サービス=のclient.getServicesを(); 
    System.out.println( "サービス一覧=" + サービス)。
    
    リスト <ServiceInstance>インスタンス=のclient.getInstances( "microservicecloud-DEPT" .toUpperCase())。
    (ServiceInstanceのイン:インスタンス){ 
        System.out.printlnは(ins.getServiceId() + "\ tの" + ins.getHost()+ "\ tの" + ins.getPort()+ "\ tの" + ins.getUri ())。
    クライアント; 
}

2. [スタート]クラスのサービスの発見は、コメントを追加@EnableDiscoveryClient

3.スタートプロジェクト、訪問のhttp:// localhostを:8001 / DEPT /発見

 

おすすめ

転載: www.cnblogs.com/myitnews/p/11620525.html