SpringBoot-Feign快速搭建
- 添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
- 加注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.eden")// 扫描Feign接口所长位置
public class ConsumerFeign01Application {
public static void main(String[] args) {
SpringApplication.run(ConsumerFeign01Application.class, args);
}
}
- 测试
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author Eden
* @date 2020/5/1 16:54
*/
@FeignClient(name = "provider-ribbon")// 需要调用的服务名
public interface DemoFeign {
@RequestMapping(value = "/user")
public String test();
}
demo代码
主要是如下几个模块不要在意provider-ribbon-xx的名字没特殊含义只是一个provider节点