ProviderService.java 856 B

123456789101112131415161718192021222324252627
  1. package com.tsf.demo.consumer.proxy;
  2. import org.springframework.cloud.openfeign.FeignClient;
  3. import org.springframework.stereotype.Component;
  4. import org.springframework.web.bind.annotation.PathVariable;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestMethod;
  7. /**
  8. * 测试通过URL配置FeignClient
  9. * 使用时修改provider-ip:provider-port配置
  10. */
  11. @FeignClient(name = "provider", url = "http://127.0.0.1:18081", fallback = FeignClientFallback.class)
  12. public interface ProviderService {
  13. @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
  14. String echo(@PathVariable("str") String str);
  15. }
  16. @Component
  17. class FeignClientFallback implements ProviderService {
  18. @Override
  19. public String echo(String str) {
  20. return "tsf-fault-tolerance-" + str;
  21. }
  22. }