同样三步:
导入依赖:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>2.1.1.RELEASE</version> </dependency>
启动类加入注解:
@EnableFeignClients
设置feign的接口,name为服务注册在eureka的服务名字:
@FeignClient(name = "luckymoney") @Service public interface LuckyMoneyFeign { @PostMapping("/default/") @ResponseBody Date getTime(); }
新建controller,引入Feign接口:
@RestController public class FeignTest { @Autowired LuckyMoneyFeign luckyMoneyFeign; @GetMapping("/time") public Date getTime(){ return luckyMoneyFeign.getTime(); } }