一、使用cloud-feign整合
1.1 导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
1.2 编写customer
1.2.1 编写启动类
@SpringBootApplication
@EnableDiscoveryClient
public class CustomerApplication {
public static void main(String[] args) {
SpringApplication.run(CustomerApplication.class,args);
}
}
1.2.2 编写yml
server:
port: 9012
spring:
application:
name: customer
cloud:
nacos:
discovery:
server-addr: http://162.14.64.72:8848
management:
endpoints:
web:
exposure:
include: "*"
1.2.3 编写comtroller
@RestController
@RequestMapping(value = "customer")
public class TestCustomerComtroller {
@Value("${server.port}")
private String port;
@GetMapping("/test")
public String test(){
System.out.println("customer port:"+port);
return port;
}
}
1.3 编写pulisher
1.3.1 编写controller
@RestController
@RequestMapping("publisher")
public class PublisherController {
@Autowired
private CostomerFeignClient costomerFeignClient;
@GetMapping("/test")
public String test(){
String test = costomerFeignClient.test();
return test;
}
}
1.3.2 编写feignclient
@FeignClient(value = "customer")
public interface CostomerFeignClient {
@RequestMapping("/customer/test")
public String test();
}
1.4 测试