美文网首页
Boot 服务 直接使用OpenFeign来使用

Boot 服务 直接使用OpenFeign来使用

作者: Spring_java | 来源:发表于2021-07-17 00:38 被阅读0次

服务提供者:
只是简单的boot,没有使用Cloud

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.1.0.RELEASE</version>
        </dependency>

代码:
@FeignClient(name = "demo")
public interface HelloClient {
    @GetMapping("/hello") //被调用接口的请求类型
    String test();
}

@RestController
public class TestController {

    @GetMapping("/hello")
    public String test(HttpServerRequest request){
        return "hello";
    }
}

@SpringBootApplication
@EnableFeignClients
public class FeignApp8009 {
    public static void main(String[] args) {
        SpringApplication.run(FeignApp8009.class);
    }
}

服务调用者:

        <dependency>
            <groupId>com.spring.boot</groupId>
            <artifactId>Boot-Feign</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

    @Autowired
    HelloClient helloClient;

    @GetMapping("/helloTest")
    public String feign(){
        String test = helloClient.test();
        return test;
    }

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

启动服务调用者 和 启动服务提供者

请求:localhost:8002/helloTest
返回:hello

相关文章

网友评论

      本文标题:Boot 服务 直接使用OpenFeign来使用

      本文链接:https://www.haomeiwen.com/subject/nxvipltx.html