feign框架的demo

maven依赖

        
            org.springframework.cloud
            spring-cloud-starter-openfeign
			3.1.5
        

使用方法

1.启动类上加上@EnableFeignClients注解

@SpringBootApplication
@EnableFeignClients
public class TestFeignApplication {

    public static void main(String[] args) {
        SpringApplication.run(TestFeignApplication.class, args);
    }

}

2.编写接口类

需要配置url和path

@FeignClient(name="test",url="127.0.0.1:8089",path = "/api/v1")
public interface TestClient {

    @GetMapping("/test")
    String test();
}

如何调用

将刚刚的接口注入到我们要使用的类中

@RestController
@RequiredArgsConstructor
public class TestCon {
    
    private final TestClient testClient;

    @GetMapping("/test")
    @ResponseBody
    public String test(){
        return testClient.test();
    }
}

你可能感兴趣的:(Tenet,java,spring,spring,boot)