FeignClient外部http请求

1 篇文章 0 订阅
1 篇文章 0 订阅

springboot 4.0.0

  1. pom.xml 引入openfeign 2.0.2
<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-openfeign</artifactId>
				<version>2.0.2.BUILD-SNAPSHOT</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
<!--外部http请求 FeignClient-->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-openfeign</artifactId>
		</dependency>
</dependencies>
<repositories>
		<!--外部http请求 FeignClient-->
		<repository>
			<id>spring-snapshots</id>
			<name>Spring Snapshots</name>
			<url>https://repo.spring.io/libs-snapshot</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
		</repository>
	</repositories>
  1. 启动类 添加注解@EnableFeignClients
@SpringBootApplication
@MapperScan("com.sichuang.repository.dao")//将项目中对应的mapper类的路径加进来就可以了
@ServletComponentScan
@EnableFeignClients
public class RepositoryApplication extends SpringBootServletInitializer{

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

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		// TODO Auto-generated method stub
//      return super.configure(builder);
		return builder.sources(RepositoryApplication.class);
	}
}

  1. 外部接口类。调用方式同service
  • @RequestParam 参数注解
  • produces = MediaType.APPLICATION_JSON_UTF8_VALUE 返回json参数
package com.sichuang.repository.api;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;


/**
 * 对接接口
 *
 * @author xs
 * @date 2018/10/8 9:08
 */
@FeignClient(url = "${url}", name = "Ewaytec2001API")
public interface Ewaytec2001API {

    /**
     */
    @GetMapping(value = "${url}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    String getEmployeeInfo(@RequestParam("id") int id, @RequestParam("sign") String sign);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值