feign
服务与服务之间的调用方式
feign默认是用ribbon,默认支持集群
@FeignClient("stores")
public interface StoreClient {
@RequestMapping(method = RequestMethod.GET, value = "/stores")
List<Store> getStores();
@RequestMapping(method = RequestMethod.POST, value = "/stores/{storeId}", consumes = "application/json")
Store update(@PathVariable("storeId") Long storeId, Store store);
}
依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
@EnableEurekaClient
@SpringBootApplication
@EnableFeignClients(clients = StudentService.class) //指定API开启
public class MyribbonApplication {
public static void main(String[] args) {
SpringApplication.run(MyribbonApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}