首页 > 其他 > 详细

@FeginClient 实例 (简单完整)

时间:2021-07-10 21:50:27      阅读:32      评论:0      收藏:0      [点我收藏+]

这里在同一个端口下演示,简单模拟一下

项目结构

技术分享图片

 

 

 

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>com-tt-web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>3.0.3</version>
        </dependency>

    </dependencies>
</project>

controller

@RestController
public class ControllerTest {

    @Autowired
    TestClient testClient;


    @RequestMapping("feign/h1")
    public String hello1(){
        System.out.println("hello1来了");
        testClient.hh();
        return "TestController hello1";
    }

    @RequestMapping("feign/h2")
    public String hello2(){
        System.out.println("hello2来了");
        return "TestController hello2";
    }

    @RequestMapping("feign/h3")
    public String hello3(){
        System.out.println("hello3来了");
        return "TestController hello3";
    }
}

client

@FeignClient(name = "testClient",url = "localhost:8080")
public interface TestClient {
    @RequestMapping("feign/h2")
    String hh();

}

  

main

@SpringBootApplication
@EnableFeignClients
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class,args);
    }
}
测试 直接浏览器输入:localhost:8080/fegin/h1
访问controller,然后controller来回转,没什么意义就是简单演示一下
 

@FeginClient 实例 (简单完整)

原文:https://www.cnblogs.com/blog-tian/p/14994520.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!