- アイデアでMavenの簡単なWebプロジェクトを作成します。
- 簡単なMavenプロジェクトにモジュールを作成します。
- moudle名前はユーレカあり、それは発見だとサービスを登録します。
-
-
サーバ: ポート:8761 ユーレカ: インスタンス: ホスト名:localhostの クライアント: registerWithEureka:偽 fetchRegistry:偽 serviceURL: defaultZoneます。http:// $ {eureka.instance.hostname}:$ {はserver.port} /ユーリカ/
ファイルに直接追加YMLプロファイル、ノーYML接尾辞、
-
アプリケーションでは、サービスレジストリは、ここで述べた@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/
- You will see this view.
- create productor.
- This project is a web, created project type is
EnableEurekaClient
-
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.
-
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); } }
- 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; } }
- Run this application,you will see this view.
-
- This project is a web, created project type is
- create su
springcloudプロジェクトが作成され
おすすめ
転載: www.cnblogs.com/hoge66/p/11986894.html
ランキング