springcloud-feign负载均衡

2020-07-09  本文已影响0人  jiahzhon

什么是Feign

Feign能干什么

简单配置

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-feign</artifactId>
  </dependency>
@FeignClient(value = "MICROSERVICECLOUD-DEPT")
public interface DeptClientService
{
 @RequestMapping(value = "/dept/get/{id}", method = RequestMethod.GET)
 public Dept get(@PathVariable("id") long id);

 @RequestMapping(value = "/dept/list", method = RequestMethod.GET)
 public List<Dept> list();

 @RequestMapping(value = "/dept/add", method = RequestMethod.POST)
 public boolean add(Dept dept);
}
@RestController
public class DeptController_Consumer
{
 @Autowired
 private DeptClientService service;

 @RequestMapping(value = "/consumer/dept/get/{id}")
 public Dept get(@PathVariable("id") Long id)
 {
  return this.service.get(id);
 }

 @RequestMapping(value = "/consumer/dept/list")
 public List<Dept> list()
 {
  return this.service.list();
 }

 @RequestMapping(value = "/consumer/dept/add")
 public Object add(Dept dept)
 {
  return this.service.add(dept);
 }
}
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(basePackages= {"com.atguigu.springcloud"})
@ComponentScan("com.atguigu.springcloud")
public class DeptConsumer80_Feign_App
{
 public static void main(String[] args)
 {
  SpringApplication.run(DeptConsumer80_Feign_App.class, args);
 }
}
上一篇下一篇

猜你喜欢

热点阅读