Spring Cloud 入门教程(三): 服务消费者(Feign)(Greenwich.RELEASE)-程序员宅基地

技术标签: python  java  

一、准备工作

同上节

二、新建maven 工程 service-feign (服务消费者 )

1、修改pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>wg</groupId>
  <artifactId>service-feign</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>service-feign</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
    <java.version>1.8</java.version>
  </properties>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <dependencies>
  	<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

2、创建启动类

package wg;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceFeignApplication {
	public static void main(String[] args) {
        SpringApplication.run( ServiceFeignApplication.class, args );
    }
}

3、创建application.yml

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

4、创建 service

package wg.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "EUREKACLIENT")
public interface HelloService {
	@RequestMapping(value = "/",method = RequestMethod.GET)
    String sayHello();
}

5、创建controller

package wg.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import wg.service.HelloService;

@RestController
public class HelloController {
    @Autowired
    HelloService helloService;

    @GetMapping(value = "/hello")
    public String sayHi() {
        return helloService.sayHello();
    }
}

6、启动项目,多次访问:http://localhost:8765/hello

e7b6bb67b80be319d5bde4bfcafa8e7efa0.jpg97a46fa1cf30397afe3912126adcdd92e9e.jpg交替出现

7、访问 http://localhost:8761

933f217b8de9022125319c5f0c18e8af2fa.jpg

项目结构:

f6b351bfd9380a002fa593a9a0e2f72537f.jpg

上一篇:Spring Cloud 入门教程(二): 服务消费者(rest+ribbon)(Greenwich.RELEASE)

转载于:https://my.oschina.net/pipi1919/blog/3059253

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_34375251/article/details/91963995

智能推荐

C++ 生成dll时没有顺带生成lib的原因_c++生成dll的同时没有lib-程序员宅基地

文章浏览阅读3.5k次。C++ dll库只生成dll文件,而未生成lib文件,问题在于没有在接口函数前面加上前缀__declspec(dllexport)在VS的工程中,此前缀常常被宏定义为:工程名_API#ifdef RADONCUDA_EXPORTS#define RADONCUDA_API __declspec(dllexport)#else#define RADONCUDA_API __declspec..._c++生成dll的同时没有lib

Android使用walle多渠道打包_android walle打包原理-程序员宅基地

文章浏览阅读846次。转载:https://github.com/Meituan-Dianping/walleWalle瓦力,Android Signature V2 Scheme签名下的新一代渠道包打包神器瓦力通过在Apk中的APK Signature Block区块添加自定义的渠道信息来生成渠道包,从而提高了渠道包生成效率,可以作为单机工具来使用,也可以部署在HTTP服务器上来实时处理渠道包Apk的升级网络请求。Q..._android walle打包原理

白嫖5T空间Onedrive并搭建下载站_企业内部下载站搭建-程序员宅基地

文章浏览阅读4.9k次。更好的阅读体验欢迎访问博客白嫖5T空间Onedrive并搭建下载站前言白嫖一个微软E5账号不仅能自己使用office全家桶,还能造福25个小伙伴,何乐而不为?这里借助onedirve的API和oneindexN项目搭建一个5T空间的公共下载站。一、获得E5账号打开Microsoft 365开发者中心点击立即加入,登陆或注册即可。公司和语言随便填写,填写信息时请自备科学上网工具,如果出现“由于存在大量请求,此服务暂时不可用”提示,需要换个时间或者换个账号再试。注册完成后打开OneDrive管理中_企业内部下载站搭建

top.index_top.indextool.xx()-程序员宅基地

文章浏览阅读2.1k次。2015年微信排行榜 body,.header,.header *,.com *,.tj_box *,.btnbox *{margin:0;padding:0;} .header,.header ul,.com ul,.tj_box ul,.btnbox ul,.header,.header li,.com li,.tj_box li,.btnbox li{list_top.indextool.xx()

AI写作生成器:节省成本亦增加风险?-程序员宅基地

文章浏览阅读506次,点赞24次,收藏5次。AI写作生成器作为一种高效的文本创造工具,在各行业中得以广泛应用。尽管它可提高工作效率与节约成本,但亦存在显著弊端。此文将多方面解析这一弊处,并探讨或许产生的不良后果。1.缺乏人文情感尽管人工智能撰写的文章生成器能够快速生成海量文本

基于SpringBoot+Vue兽医站管理系统的设计与实现-程序员宅基地

文章浏览阅读817次,点赞18次,收藏26次。在此基础上,结合现有兽医站体系的特点,运用新技术,构建了以springboot为基础的兽医站信息化管理体系。首先,以需求为依据,根据需求分析结果进行了系统的设计,并将其划分为管理员和员工二种角色和多个主要模块:员工、考勤签到、动物类型、动物信息、动物日常、观察记录、健康检测、记录存档等。使用目前市场主流的技术springboot框架进行项目构建,基于B/S架构开发模式,使用Java开发语言和MySQL数据库对系统进行高内聚低耦合的设计,最终完成了兽医站管理系统的实现。

随便推点

Flask 使用 request 处理GET POST请求、上传文件_request.files.get-程序员宅基地

文章浏览阅读6.2k次,点赞5次,收藏23次。在Django框架开发中,request对象就是用来处理GET\POST请求的关键对象,而Flask框架也是一样的。下面来看看request对象的常用方法。request对象的常用方法request对象的导入:from flask import requestFlask 框架中的 request 对象保存了一次HTTP请求的一切信息。那么这个HTTP请求中可能会是GET..._request.files.get

vue实现的分段式进度条(步骤条结合进度条)_vue分段式进度条-程序员宅基地

文章浏览阅读8.2k次,点赞8次,收藏52次。作为一个前端初学者,公司项目中前端需要一个带分步式的进度条,查查Element-ui和Ant design Vue都只有_vue分段式进度条

RecyclerView中的item点击事件_.rvonitemclicklistener.onclick(int)-程序员宅基地

文章浏览阅读494次。1.在adapter中:private RecyclerView rv;@Overridepublic void onAttachedToRecyclerView(RecyclerView recyclerView) { super.onAttachedToRecyclerView(recyclerView); rv = recyclerView;}public_.rvonitemclicklistener.onclick(int)

第五节“LMDeploy量化部署”笔记-程序员宅基地

文章浏览阅读605次,点赞12次,收藏27次。图文大模型量化部署

英飞凌 AURIX 系列单片机的HSM详解(3)——开发方法_tc397 hsm-程序员宅基地

文章浏览阅读9.4k次,点赞12次,收藏82次。点击回顾之前的文章:《英飞凌 AURIX 系列单片机的HSM详解(1)——何为HSM》《英飞凌 AURIX 系列单片机的HSM详解(2)——与HSM相关的UCB和寄存器》本文以TC397为例,来介绍一下HSM的开发方法。1. 编译器HSM开发时分两个工程,一个工程是编译Tricore内核代码的,用到的编译器是Tasking for Tricore;另一个工程是编译HSM的ARM Cortex-M3内核的,用的是Tasking ARM for HSM。各个版本可以在下面Tasking的官网上找到_tc397 hsm

C语言指针操作(六)指向函数的指针-程序员宅基地

文章浏览阅读5.2k次,点赞27次,收藏80次。指向函数的指针详解,以及如何使用指向函数的指针变量做函数参数。指向函数的指针作为函数参数,是 C 语言实际应用中的一个比较深入的部分。_指向函数的指针

推荐文章

热门文章

相关标签