<!--feign-->
  <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
  </dependency>
@FeignClient(value = "provider-person-8001")
public interface PersonService {
    @GetMapping("/person/{id}")
    Person getPersonById(@PathVariable("id") Integer id);
    @GetMapping("/person/getall")
    List<Person> personAll();
    @PostMapping("person/add")
    void addPerson(Person person);
}
@RestController
public class PersonController {
    @Autowired(required = false) //没注入,编译过不去,不影响使用
    PersonService personService;
    @GetMapping("/person/all")
    public List<Person> getall(){
        return personService.personAll();
    }
    @GetMapping("/person/addpe")
    public Void getall(@RequestParam("name") String name, @RequestParam("age")int age){
        Person person = new Person();
        person.setName(name);
        person.setAge(age);
        person.setPerm("user:add");
        personService.addPerson(person);
        return null;
    }
    @GetMapping("person/get/{id}")
    public Person getall(@PathVariable("id") int id){
        return personService.getPersonById(id);
    }
}
@SpringBootApplication
@EnableEurekaClient //为Eureka客户端
@EnableFeignClients(basePackages = {"cn.lzm.springcloud"}) //指定扫描的包
public class PersonConsumerApplication_Feign {
    public static void main(String[] args) {
        SpringApplication.run(PersonConsumerApplication_Feign.class,args);
    }
}
原文:https://www.cnblogs.com/xiaominaaaa/p/14261814.html