feign学习

feign集成了ribbon,只需要新建接口加注解即可

 <!--feign相关-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>

 接口:

@FeignClient(value = "MICROSERVICECLOUD")
public interface TestClientService {


    @RequestMapping(value = "/person/add")
    public boolean add(Person  person);

}

controller:

@RestController
public class TestController {

    //private static final String REST_URL_PREFIX = "http://localhost:8001";
   // private static final String REST_URL_PREFIX = "http://MICROSERVICECLOUD";

    @Autowired
    privateTestClientService testClientService;

    @RequestMapping(value = "/consumer/person/add")
    public boolean add(Person person){
        return testClientService.add(person);
    }
}

主启动类:

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(basePackages ={ "com.test.microservicecloud"})
@ComponentScan("com.test.microservicecloud")
public class TestConsumer {
    public static void main(String[] args) {
        SpringApplication.run TestConsumer.class,args);
    }
}

 

posted on 2018-08-17 13:13  Java挖掘机  阅读(144)  评论(0编辑  收藏  举报

导航