springcloudプロジェクトが作成され

  1. アイデアでMavenの簡単なWebプロジェクトを作成します。
  2. 簡単なMavenプロジェクトにモジュールを作成します。
    1. moudle名前はユーレカあり、それは発見だとサービスを登録します。
    2.  

       

    3. サーバ:
        ポート:8761
      
      ユーレカ:
        インスタンス:
          ホスト名:localhostの
        クライアント:
          registerWithEureka:偽
          fetchRegistry:偽
          serviceURL:
            defaultZoneます。http:// $ {eureka.instance.hostname}:$ {はserver.port} /ユーリカ/
      

        ファイルに直接追加YMLプロファイル、ノーYML接尾辞、

    4.  

       アプリケーションでは、サービスレジストリは、ここで述べた@EnableEurekaServerコメントを追加します。

      パッケージcom.bcd.cloud.pf.eureka。
      
      輸入org.springframework.boot.SpringApplication。
      輸入org.springframework.boot.autoconfigure.SpringBootApplication。
      輸入org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
      
      / **
       * EurekaApplicationクラス
       *
       * @EnableEurekaServerは、自分で作成されました
       *
       *自分@author
       * @date 2019年12月5日
       * /
      @SpringBootApplication
      @EnableEurekaServer
      public class EurekaApplication {
      
      	public static void main(String[] args) {
      		SpringApplication.run(EurekaApplication.class, args);
      	}
      
      }
      

        Start this project,and view in the web explorer.http://localhost:8761/

    5. You will see this view.

       

       

  3. create productor.
    1. This project is a web, created project type is 
      EnableEurekaClient
    2. eureka:
        client:
          serviceUrl:
            defaultZone: http://localhost:8761/eureka/
      server:
        port: 8763
      spring:
        application:
          name: productor
      

        productor was set eureka client,it will discovery by 8761,but its port is 8763.

    3. package com.bcd.cloud.pf.productor;
      
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
      
      /**
       * ProductorApplication class
       *
       * @EnableEurekaClient was created by myself
       *
       * @author myself
       * @date 2019/12/05
       */
      @SpringBootApplication
      @EnableEurekaClient
      public class ProductorApplication {
      
      	public static void main(String[] args) {
      		SpringApplication.run(ProductorApplication.class, args);
      	}
      
      }
      

        

    4. The APPController was added by myself.
      package com.bcd.cloud.pf.productor.rest;
      
      import org.springframework.beans.factory.annotation.Value;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestParam;
      import org.springframework.web.bind.annotation.RestController;
      
      /**
       * Demo class
       *
       * @author keriezhang
       * @date 2016/10/31
       */
      @RestController
      public class AppController {
      
          @Value("${server.port}")
          String port;
      
          @RequestMapping("/hi")
          public String home(@RequestParam String name)
          {
              return "hi " + name + ",i am from port:" + port;
          }
      }
      

        

    5. Run this application,you will see this view.
    6.  

       

       

       

  4. create su

おすすめ

転載: www.cnblogs.com/hoge66/p/11986894.html