局bのspringcloudから学び、今でエラーが発生しやすい場所のいくつかを思い出した、ビデオに登場する小さな誤差の要約除去を要約
アウトバウンドリンクB:https://www.bilibili.com/video/av55304977
データ・リンク:
https://pan.baidu.com/s/1o0Aju3IydKA15Vo1pP4z5w
抽出コード:21ru
:リンクではhttps://blog.csdn.net/qq_40893824/article/details/103332091
次のセクションへのリンク:https://blog.csdn.net/qq_40893824/article/details/103336449
次のリストまとめています。サブプロジェクト→ポンポン→アプリケーション→学生→ハンドラ→エンティティクラスのクラスがスタート
実装の詳細:
1.リボンという名前のモジュールモジュール、作成し
たコードを追加し、モジュールのPOMファイル2.:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
</dependencies>
リソース3.チョンapplication.ymlは、コードを追加します。
server:
port: 8040
spring:
application:
name: ribbon
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka/
instance:
prefer-ip-address: true
#确认注册
Javaのパッケージレコードのcom.southwind 4.、サウスウィンドスタートでクラスRibbonApplication.javaを作成し、コード内の塗りつぶし:漏れない@LoadBalanced!
package com.southwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class RibbonApplication {
public static void main(String[] args) {
SpringApplication.run(RibbonApplication.class,args);
}
@Bean
@LoadBalanced//负载均衡
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
レコードサウスウィンドパッケージエンティティ5.は、パケット生徒にコピーする
コードを追加し、RibbonHandler.javaを作成、記録サウスウィンドパケット制御で6:
package com.southwind.controller;
import com.southwind.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.Collection;
@RestController
@RequestMapping("/ribbon")
public class RibbonHandler {
@Autowired
private RestTemplate restTemplate;
@GetMapping("/findAll")
public Collection<Student> findAll(){
return restTemplate.getForObject("http://provider/student/findAll",Collection.class);
}
@GetMapping("/index")
public String index(){
return restTemplate.getForObject("http://provider/student/index",String.class);
}
}
7.チェックを介して転送
入るHTTP :. // localhostを:8761
B入力します。http :. // localhostを:8040 /リボン/インデックス・
ポートは、ページを更新するF5 8010です。
このポートは8010と8011の間で変換された、それはあります負荷分散の機能を実現しました。
それでアップチェックするようにコードを変更するには追加および削除する前に、コピーを追加するのは簡単ですので、ここで私は、条件を変更して再検索への書き込みコードの追加および削除する必要はありません。
zuulとリボンはspringcloud白として、私はzuul現在リボンよりも簡単だと思う動作し、負荷分散されています。
:リンクではhttps://blog.csdn.net/qq_40893824/article/details/103332091
次のセクションへのリンク:https://blog.csdn.net/qq_40893824/article/details/103336449