添加依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> <version>1.4.2.RELEASE</version> </dependency>
启动类添加注解@EnableFeignClients
@SpringBootApplication @EnableDiscoveryClient @EnableFeignClients public class OrderApplication { public static void main(String[] args) { SpringApplication.run(OrderApplication.class, args); } }
声明调用哪个应用
@FeignClient(name="product") @Component public interface ProductClient { @GetMapping("/msg") String productMsg(); }
调用应用
@Autowired private ProductClient productClient; @GetMapping("getMsg") public String getMsg() { String response = productClient.productMsg(); log.info("response={}", response); return response; }