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

 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:https://github.com/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);
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值