赞
踩
<!-- Open Feign,他里面也有ribbon,所以有负载均衡 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
# 我这里注册中心中的nacos
spring:
datasource:
username: root
password: root
url: jdbc:mysql://xxx.xxx.x.xx:3306/gulimall_sms?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
application:
name: gulimall-coupon
cloud:
nacos:
discovery:
server-addr: 192.168.2.88:8848
@EnableDiscoveryClient//开启注册中心,注册与发现
@SpringBootApplication
public class GulimallCouponApplication {
public static void main(String[] args) {
SpringApplication.run(GulimallCouponApplication.class, args);
}
}
@RestController
public class Test {
@GetMapping("/coupon/test1")
public String test(){
return "test success!";
}
}
//com.atguigu.gulimall.product.feign是我们专门写远程调用方法的包
@EnableFeignClients("com.atguigu.gulimall.product.feign")//开启远程调用
@EnableDiscoveryClient//开启注册发现
@SpringBootApplication
public class GulimallProductApplication {
public static void main(String[] args) {
SpringApplication.run(GulimallProductApplication.class, args);
}
}
首先要创建一个接口
@FeignClient(value = "gulimall-coupon")
public interface CouponFeignService {
@GetMapping("/coupon/test1")//这里的请求地址需要和被调用的地址一样
String test();
}
@RestController
public class Test {
@Autowired
CouponFeignService couponFeignService;
//测试优惠服务的远程调用
@GetMapping("/test/test/1")
public String test(){
return couponFeignService.test();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。