码迷,mamicode.com
首页 > 编程语言 > 详细

springcloud 使用feign

时间:2021-06-16 17:34:00      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:sch   framework   script   dsc   使用   art   class   imp   hello   

一,被调用方 web-test

spring:
  application:
    name: web-test

二,web-test准备接口

package com.tenyears.webTest.controller;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping("api/test")
public class TestController {
 
 
    @RequestMapping(value = "test1", method = RequestMethod.POST)
    public String test1() {
        return "hello";
    }
 
}

三,调用方web-hello

POM

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-feign</artifactId>
    </dependency>

四,Feign

@FeignClient(value="服务名")

package com.tenyears.webAD.feign;
 
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
/**
 * @description :
 * @auther Tyler
 * @date 2021/6/15
 */
 
@FeignClient(value = "web-test")
public interface WebTestFeign {
    @RequestMapping(value = "/api/test/test1", method = RequestMethod.POST)
    String test1();
}

五,测试接口

package com.tenyears.webAD.controller;
 
import com.tenyears.webAD.feign.WebTestFeign;
import com.tenyears.webAD.service.service.AdScheduleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * @author Tyler
 * @date 2019/4/16
 */
 
@RestController
@RequestMapping("api/test")
public class TestController {
    Logger logger = LoggerFactory.getLogger(TestController.class);
 
    @Autowired
    WebTestFeign webTestFeign;
 
 
    @RequestMapping(value = "test1", method = RequestMethod.POST)
    public String test1() {
        String str=webTestFeign.test1();
        return str;
    }
 
}

 

springcloud 使用feign

标签:sch   framework   script   dsc   使用   art   class   imp   hello   

原文地址:https://www.cnblogs.com/hanjun0612/p/14886309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!