ナコスサービス発見のSpringCloud(XVI)

サービス・プロバイダー構成

  • pom.xml

 <依存>
        <groupIdを> org.springframework.boot </ groupIdを>
        <たartifactId>春・ブート・スターター・ウェブ</たartifactId>
    </依存関係>
    <! - ナコスでは、問題のバージョンに注意を払う必要があります - >
    <依存>
        <groupIdを> org.springframework.cloud </ groupIdを>
        <たartifactId>ばねクラウドスタータアリババ-ナコス発見</たartifactId>
        <バージョン> 0.9.0.RELEASE </バージョン>
    </依存関係>
</依存関係>

 

  • application.yml

    サーバ:
      ポート: 8881
    春:
      応用:
        名前:ナコス - 製品
      雲:
        ナコス:
          発見:
            サーバー -addr:192.168.180.113:8848

     

  • スタートアップクラス

    @SpringBootApplication
    @EnableDiscoveryClient
    パブリック クラスNacosProductApplication {
    
        パブリック 静的 ボイドメイン(文字列[]引数){
            SpringApplication.run(NacosProductApplication。クラス、引数)。
        }
    
    }
     
  • ウェブ層

    1  / ** 
    2  * @author WGR
     3  * @Create 2019年10月25日-午後12時29分
     4   * / 
    5  @RestController
     6 @RequestMapping( "/ユーザ" 7つの パブリック クラスUserControllerで{
     8      @GetMapping
     9      公共の文字列のgetUser (){
     10          リターン "管理者" 11      }
     12 }

     

テスト結果:

IIは、消費者のコンフィギュレーションを提供します

  • pom.xml

    <依存>
                <groupIdを> org.springframework.cloud </ groupIdを>
                <たartifactId>ばねクラウドスタータopenfeign </たartifactId>
            </依存関係>
            <! - ウェブ - >
            <依存>
                <groupIdを> org.springframework.boot </ groupIdを>
                <たartifactId>春・ブート・スターター・ウェブ</たartifactId>
            </依存関係>
    
            <! - ナコスでは、問題のバージョンに注意を払う必要があります - >
            <依存>
                <groupIdを> org.springframework.cloud </ groupIdを>
                <たartifactId>ばねクラウドスタータアリババ-ナコス発見</たartifactId>
                <バージョン> 0.9.0.RELEASE </バージョン>
            </依存関係>
            <依存>
                <groupIdを> org.springframework.boot </ groupIdを>
                <たartifactId>ばねブートスタータ試験</たartifactId>
                <スコープ>テスト</スコープ>
                <除外>
                    <除外>
                        <groupIdを> org.junit.vintage </ groupIdを>
                        <たartifactId> JUnitのヴィンテージエンジン</たartifactId>
                    </除外>
                </除外>
            </依存関係>
        </依存関係>

     

  • application.yml

    サーバ:
      ポート: 8882
    春:
      応用:
        名前:ナコス - 消費者
      雲:
        ナコス:
          発見:
            サーバー -addr:192.168.180.113:8848

     

  • スタートアップクラス構成

    @SpringBootApplication
    @EnableFeignClients
    パブリック クラスNacosConsumerApplication {
    
        パブリック 静的 ボイドメイン(文字列[]引数){
            SpringApplication.run(NacosConsumerApplication。クラス、引数)。
        }
    
    }
    

     

  • ウェブ層

    / ** 
     * @author WGR
     * @Createの2019年10月25日 - 午後12時46分
     * /
    @RestController
    @RequestMapping( "/テスト" パブリック クラスTestController {
    
        @Autowired(必須 = プライベートTestService testService。
    
        @GetMapping( "/ユーザ" パブリック文字列のgetUser(){
             戻り)(testService.getUserします。
        }
    }

     

  • サービス層

    / ** 
     * @author WGR
     * @Createの2019年10月25日 -  0時47分
     * / 
    @FeignClient( "ナコス副生成物" パブリック インターフェースTestService {
    
        @GetMapping( "ユーザー" 
        ストリングのgetUser()。
    
    }

    テスト:HTTP:// localhostを:8882 /テスト/ユーザー

 

おすすめ

転載: www.cnblogs.com/dalianpai/p/11735937.html