首页 > 编程知识 正文

feign实例,Feign调用

时间:2023-05-05 00:06:15 阅读:204294 作者:1673

1、maven
sb版本要比sc版本一样,或者比sc高

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>2.1.2.RELEASE</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>2.1.1.RELEASE</version></dependency>

2、启动类

@EnableFeignClients(basePackages={"com.*"})public class WmsApplication {public static void main(String[] args) {SpringApplication.run(WmsApplication.class, args);} }

3、使用案例

import org.springframework.cloud.openfeign.FeignClient;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import com.alibaba.fastjson.JSONObject;@FeignClient(url= "${test_url}",name="client")public interface TestClient { @RequestMapping(value="${test_token}",method= RequestMethod.GET) JSONObject getAccessToken(@RequestParam("grant_type") String grant_type,@RequestParam("appid") String appid,@RequestParam("secret") String secret); @RequestMapping(value="${test_getticket}",method= RequestMethod.GET) JSONObject getTicket(@RequestParam("access_token") String access_token,@RequestParam("type") String type); @RequestMapping(value="${test_oauth2_access_token}",method= RequestMethod.GET) String getOpenId(@RequestParam("appid") String appid,@RequestParam("secret") String secret,@RequestParam("code") String code,@RequestParam("grant_type") String grant_type); @RequestMapping(value="${test_menu_create}",method= RequestMethod.POST) JSONObject menuCreate(@RequestParam("access_token") String accessToken,@RequestBody(required=false)String jsonResult);}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。