博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringCloud+feign 基于Springboot2.0 负载均衡
阅读量:4352 次
发布时间:2019-06-07

本文共 4428 字,大约阅读时间需要 14 分钟。

pom.xml

4.0.0
com.ggr
feign
0.0.1-SNAPSHOT
jar
springcloudService-feign
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
2.0.2.BUILD-SNAPSHOT
UTF-8
UTF-8
1.8
Finchley.BUILD-SNAPSHOT
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
spring-snapshots
Spring Snapshots
https://repo.spring.io/snapshot
true
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false
spring-snapshots
Spring Snapshots
https://repo.spring.io/snapshot
true
spring-milestones
Spring Milestones
https://repo.spring.io/milestone
false

App

package com.ggr.feign;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.openfeign.EnableFeignClients;@SpringBootApplication@EnableDiscoveryClient@EnableFeignClientspublic class SpringcloudServiceFeignApplication {	public static void main(String[] args) {		SpringApplication.run(SpringcloudServiceFeignApplication.class, args);	}}

  

  Controller

package com.ggr.feign.controller;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HiController {    @Autowired    HystrixClient schedualServiceHi;    @RequestMapping(value = "/hi",method = RequestMethod.GET)    public String sayHi(@RequestParam String name){        return schedualServiceHi.sayHiFromClientOne(name);    }}

  

FeignClient

package com.ggr.feign.controller;import org.springframework.cloud.openfeign.FeignClient;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;@FeignClient(value="service-hi",fallback=HystrixClientFallbackFactory.class)public interface HystrixClient  {	@RequestMapping(value = "/hi",method = RequestMethod.GET)    String sayHiFromClientOne(@RequestParam(value = "name") String name);}

  application.yml

eureka:  client:    serviceUrl:      defaultZone: http://localhost:9000/eureka/server:  port: 9005spring:  application:    name: service-feign

  

 

转载于:https://www.cnblogs.com/imggr/p/8967903.html

你可能感兴趣的文章
eclipse debug (调试) 学习心得
查看>>
有哲理的一段话
查看>>
TCP协议中的三次握手和四次挥手(图解)
查看>>
智能指针 线程变量
查看>>
linux:vi报错“Can’t write viminfo file /root/.viminfo!”
查看>>
PostgreSQL中如何得到一个随机的字符
查看>>
bulk insert 在mssql中使用
查看>>
兼容IE,Firefox,chrome等浏览器 : 设为首页和收藏的Javascript代码
查看>>
控件的局部圆角问题
查看>>
设计师必看的25个优秀的移动界面设计案例
查看>>
Skippr – 轻量、快速的 jQuery 幻灯片插件
查看>>
12款高质量的免费 CSS 网站模板下载
查看>>
winform Label与DataGridView右对齐 分类: WinF...
查看>>
VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号
查看>>
POJ 1734 求最小环路径 拓展Floyd
查看>>
m个相同苹果放的n个相同盘子中的算法
查看>>
[置顶] 学习VB.NET编程最基本的三个问题
查看>>
Appium+eclipse+python环境配置
查看>>
elasticSearch-DSL
查看>>
Python多继承之MRO算法
查看>>