个人前置环境nacos 作为注册中心
nacos配置以及踩坑
1.open-feign 是一个声明式的远程调用
首先导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</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>
2.编写接口服务消费方
这里在spring 的启动类的同级目录中创建了一个feign包用来存放远程调用接口
消费方接口参数
@FeignClient(“market-coupon”)
这个注解就是告诉feign调用哪个服务
@RequestMapping("/marketcoupon/coupon/meber/list")
这个注解里面的参数注意是服务提供方contorller里完整的接口路径
声明接口的每一个方法调用的是哪个服务的哪个接口
类路径+方法路径
服务提供方
3.开启远程调用
使用注解@EnableFeignClients(basePackages = “com.it.market.marketmember.feign”)
扫描接口包
4.测试
服务消费方测试类
启动服务,
这里启动了一个7000端口的服务提供者
8000端口的服务消费者
访问接口