一、使用cloud-feign整合
    1.1 导入依赖

    1. <dependency>
    2. <groupId>org.springframework.cloud</groupId>
    3. <artifactId>spring-cloud-starter-openfeign</artifactId>
    4. </dependency>

    1.2 编写customer
    1.2.1 编写启动类

    1. @SpringBootApplication
    2. @EnableDiscoveryClient
    3. public class CustomerApplication {
    4. public static void main(String[] args) {
    5. SpringApplication.run(CustomerApplication.class,args);
    6. }
    7. }

    1.2.2 编写yml

    1. server:
    2. port: 9012
    3. spring:
    4. application:
    5. name: customer
    6. cloud:
    7. nacos:
    8. discovery:
    9. server-addr: http://162.14.64.72:8848
    10. management:
    11. endpoints:
    12. web:
    13. exposure:
    14. include: "*"

    1.2.3 编写comtroller

    1. @RestController
    2. @RequestMapping(value = "customer")
    3. public class TestCustomerComtroller {
    4. @Value("${server.port}")
    5. private String port;
    6. @GetMapping("/test")
    7. public String test(){
    8. System.out.println("customer port:"+port);
    9. return port;
    10. }
    11. }

    1.3 编写pulisher
    1.3.1 编写controller

    1. @RestController
    2. @RequestMapping("publisher")
    3. public class PublisherController {
    4. @Autowired
    5. private CostomerFeignClient costomerFeignClient;
    6. @GetMapping("/test")
    7. public String test(){
    8. String test = costomerFeignClient.test();
    9. return test;
    10. }
    11. }

    1.3.2 编写feignclient

    1. @FeignClient(value = "customer")
    2. public interface CostomerFeignClient {
    3. @RequestMapping("/customer/test")
    4. public String test();
    5. }

    1.4 测试
    image.png