实现
1、添加依赖
<!-- SpringCloud Openfeign --> <dependency> <artifactId>spring-cloud-starter-openfeign</artifactId> <groupId>org.springframework.cloud</groupId> <version>${openfeign.version}</version> </dependency>
2、创建一个Feign接口,并添加@FeignClient注解
@FeignClient(contextId = "remoteRuleService", value = ServiceNameConstants.THINGLINKS_RULE, fallbackFactory = RemoteRuleFallbackFactory.class) public interface RemoteRuleService { @GetMapping("/ruleAlarmList/newListByid/{id}") public TableDataInfo newListByDeviceIdentification(@PathVariable(value = "id") String id); }
3、修改启动类,为其添加@EnableFeignClients注解
@EnableCustomConfig @EnableCustomSwagger2 @EnableRyFeignClients @EnableScheduling @Async @CrossOrigin(origins = "*", maxAge = 3600) @SpringBootApplication(scanBasePackages = {"com.aaa"}) public class ThingLinksLinkApplication { public static void main(String[] args) { SpringApplication.run(ThingLinksLinkApplication.class, args); System.out.println("(♥◠‿◠)ノ゙ Link模块启动成功 ლ(´ڡ`ლ)゙ "); } }
4、修改Controller代码,让其调用Feign接口
remoteRuleService./ruleAlarmList/newListById(id);