springcloud - alibaba - 2 - 集成Feign - 更新完成
1、依赖
- 依赖管理
<parent>
<artifactId>spring-boot-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.3.12.RELEASE</version>
<relativePath/>
</parent>
- 项目需要的依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- springcloud-alibaba需要的依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR12</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
2、服务提供者
2.1)、yml配置
server:
port: 8011
spring:
application:
name: ALIBABA-PUBLISHER
cloud:
nacos:
discovery:
server-addr: 162.14.66.60:8848 # 自己的服务器ip:8848
management:
endpoints:
web:
exposure:
include: "*" #健康检查
2.2)、启动类编写
package cn.zixieqing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @ClassName PublisherApplication
* @Author ZiXieQing
* @Date 2021/12/7
* Version 1.0
**/
@SpringBootApplication
@EnableDiscoveryClient // 开启nacos的客户端功能
public class PublisherApplication {
public static void main(String[] args) {
SpringApplication.run(PublisherApplication.class, args);
}
}
2.3)、controller编写
package cn.zixieqing.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/provider")
public class ProvideService {
@GetMapping("/service")
public String provideService() {
return "this is my son";
}
}
3、Feign
3.1)、导入依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
3.2)、编写yml
server:
port: 8012
spring:
cloud:
nacos:
discovery:
server-addr: 162.14.66.60:8848 # 自己的服务器ip:8848
application:
name: ALIBABA-OPENFEIGN
3.3)、接口编写
package cn.zixieqing;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(value = "ALIBABA-PUBLISHER") // publisher中注册进去的服务名
public interface ProxyService {
@RequestMapping(value = "/provider/service" , method = RequestMethod.GET)
String provideService();
}
3.4)、启动类编写
package cn.zixieqing;
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
@EnableFeignClients
public class OpenFeignApplication {
public static void main(String[] args) {
SpringApplication.run(OpenFeignApplication.class, args);
}
}
3.5)、服务消费层编写
package cn.zixieqing.controller;
import cn.zixieqing.ProxyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @ClassName getService
* @Author ZiXieQing
* @Date 2021/12/7
* Version 1.0
**/
@RestController
@RequestMapping("/test")
public class getService {
@Autowired
private ProxyService proxyService;
@GetMapping("/getService")
public String getServer() {
return proxyService.provideService();
}
}
4、启动publisher 和 Feign
springcloud - alibaba - 2 - 集成Feign - 更新完成的更多相关文章
- springcloud - alibaba - 3 - 整合config - 更新完毕
0.补充 1.需求 如果我有这么一个请求:我想要gitee中的配置改了之后,我程序yml中的配置也可以跟着相应产生变化,利用原生的方式怎么做?一般做法如下: 而有了SpringCloud-alibab ...
- 十一. SpringCloud Alibaba
1. SpringCloud Alibaba简介 1.1 为什么会出现SpringCloud Alibaba Spring Cloud Netflix项目进入到维护模式 什么是维护模式?=> 将 ...
- SpringCloud Alibaba微服务实战三 - 服务调用
导读:通过前面两篇文章我们准备好了微服务的基础环境并让accout-service 和 product-service对外提供了增删改查的能力,本篇我们的内容是让order-service作为消费者远 ...
- SpringCloud系列之集成分布式事务Seata应用篇
目录 前言 项目版本 项目说明 Seata服务端部署 Seata客户端集成 cloud-web module-order module-cart module-goods module-wallet ...
- SpringCloud Alibaba实战(7:nacos注册中心管理微服务)
源码地址:https://gitee.com/fighter3/eshop-project.git 持续更新中-- 在上一节我们已经完成了Nacos Server的本地部署,这一节我们学习如何将Nac ...
- SpringCloud Alibaba实战(8:使用OpenFeign服务调用)
源码地址:https://gitee.com/fighter3/eshop-project.git 持续更新中-- 在上一个章节,我们已经成功地将服务注册到了Nacos注册中心,实现了服务注册和服务发 ...
- SpringCloud Alibaba实战(9:Hystrix容错保护)
源码地址:https://gitee.com/fighter3/eshop-project.git 持续更新中-- 在上一节我们已经使用OpenFeign完成了服务间的调用.想一下,假如我们一个服务链 ...
- 【springcloud alibaba】注册中心之nacos
1.为什么需要注册中心 1.1 没有注册中心会怎么样 1.2 注册中心提供什么功能以及解决什么问题 2.常用的微服务注册中心对比 3.案例项目父工程 4.nacos作为注册中心的使用 4.1 单机版的 ...
- SpringCloud Alibaba入门之Nacos(SCA)
SpringCloud Alibaba Spring Cloud Alibaba 致力于提供微服务开发 的一站式解决方案.此项目包含开发分布式应用微服务的必需组件,方便开发者通过 Spring Clo ...
随机推荐
- 洛谷 P6075 [JSOI2015]子集选取
链接:P6075 前言: 虽然其他大佬们的走分界线的方法比我巧妙多了,但还是提供一种思路. 题意: %&¥--@#直接看题面理解罢. 分析过程: 看到这样的题面我脑里第一反应就是DP,但是看到 ...
- Git 极速上手(超简单)
前言:本文主要介绍了一种快速入门使用Git的方法,通过四步完成本地仓库构建和推送到远程仓库(Github.Gitee码云),简单说明最常用的命令,不需要明白Git的原理即可使用,本文不介绍具体原理. ...
- 彻底解决SLF4J的日志冲突的问题
今天公司同事上线时发现,有的机器打印了日志,而有的机器则一条日志也没有打.以往都是没有问题的. 因此猜测是这次开发间接引入新的日志jar包,日志冲突导致未打印. 排查代码发现,系统使用的是SLF4J框 ...
- Swoft+Docker
Docker 以下纯属个人理解: Docker就是一种虚拟机,将环境打包成镜像,等于做了一个Linux系统裁剪. 镜像就是我们安装系统的镜像,里面包含了你的代码和环境. 容器就是一个虚拟机,你可以用一 ...
- Sentinel-Go 源码系列(二)|初始化流程和责任链设计模式
上节中我们知道了 Sentinel-Go 大概能做什么事情,最简单的例子如何跑起来 其实我早就写好了本系列的第二篇,但迟迟没有发布,感觉光初始化流程显得有些单一,于是又补充了责任链模式,二合一,内容显 ...
- Fiddler抓包工具简介:(四)Fiddler的基本使用
Fiddler的使用 视图功能区域 会话的概念:一次请求和一次响应就是一个会话. fiddler主界面 下面挑几个快捷功能区中常用几项解释,其他功能自己尝试: 快捷功能区 1:给会话添加备注信息 2: ...
- elementUI合并表格span-method用法
官方文档 参考链接一 参考链接二
- PTA 最小堆插入元素和删除堆顶(无哨兵元素) (20分)
PTA 最小堆插入元素和删除堆顶(无哨兵元素) (20分) 对于给定的最小堆(优先队列),分别实现插入元素和删除堆顶的函数. 函数接口定义: int insertIntoHeap(struct Hea ...
- 在k8s中收集jvm异常dump文件到OSS
现状 加参数 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=logs/test.dump 可以实现在jvm发生内存错误后 会生成dump文件 方便开 ...
- 【数据结构&算法】12-线索二叉树
目录 前言 线索二叉树的概念 线索二叉树的实现 线索二叉树的寻点思路二 类双向链表参考图 参考代码 中序遍历线索化 前言 在<大话数据结构>P190 页中有一句话:其实线索二叉树,就等于是 ...