100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 微服务-注册中心 配置中心 网关

微服务-注册中心 配置中心 网关

时间:2022-08-10 01:19:01

相关推荐

微服务-注册中心 配置中心 网关

pom.xml

<!--服务注册/发现--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--配置中心来做配置管理--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency>

1、Spring Cloud Alibaba -Nacos [作为注册中心]
1)、spring-cloud-alibaba:/alibaba/spring-cloud-alibaba
2)、 nacos文档:Nacos 快速开始
3)、下载 Nacos Server
4)、启动Nacos Server

a、双击bin中的startup.cmd文件

b、访问 http://localhost:8848/nacos/

c、使用默认的nacos/nacos进行登录

5)、将微服务注册到nacos

a 、修改pom.xml,引入Nacos Discovery Starter

<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>

b、在application.yml配置文件中配置nacos地址

spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848

c、使用 @EnableDiscoveryClient开启服务注册发现功能

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

d、启动应用,查看nacos服务列表是否已经注册服务

6)、feign的远程调用

a、引入open-feign

b、开启@EnableFeignClients(basePackages = "xxx.xxx.xxx")

c、编写接口,进行远程调用

/*** 这是一个声明式的远程调用*/

@FeignClient("stores")public interface StoreClient {@RequestMapping(method = RequestMethod.GET, value = "/stores")List<Store> getStores();@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")Store update(@PathVariable("storeId") Long storeId, Store store);}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。