实例SerivceImplOrder
注: SerivceImplOrder 2020 调用<OpenFeign> SerivceImplMember2019
i)、pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.netflix.archaius</groupId>
<artifactId>archaius-core</artifactId>
<version>0.7.6</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
ii)、MemberServiceFeign
@FeignClient("ServiceImplMember")
public interface MemberServiceFeign {
@GetMapping("/getUser")
public String getUser(@RequestParam("useId") Integer useId);
iii)、OrderService
@RestController
public class OrderService {
@Autowired
private MemberServiceFeign memberServiceFeign;
@RequestMapping("/orderFeignToMember")
public String orderFeignToMember(){
String result=memberServiceFeign.getUser(1);
return "【ServiceImplOrder 2020】我是订单服务调用会员服务【ServiceImplMember 2019】的接口"+result;
}
}
iiii)、Application
@SpringBootApplication
@EnableFeignClients
public class ServiceImplOrderApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceImplOrderApplication.class, args);
}
}
iiiii)、application.properties
# 应用名称
spring.application.name=ServiceImplOrder
# 应用服务 WEB 访问端口
server.port=2020
# Nacos帮助文档: https://nacos.io/zh-cn/docs/concepts.html
# Nacos认证信息
spring.cloud.nacos.discovery.username=nacos
spring.cloud.nacos.discovery.password=nacos
# Nacos 服务发现与注册配置,其中子属性 server-addr 指定 Nacos 服务器主机和端口
spring.cloud.nacos.discovery.server-addr=http://127.0.0.1:8848
# 注册到 nacos 的指定 namespace,默认为 public
spring.cloud.nacos.discovery.namespace=public
iiiiii)、