Dry food sharing microservices Spring-cloud (5. Declarative service call feign)

Source: Internet
Author: User

Spring Cloud Feignbased onNetflix Feignimplementation, integration ofSpring Cloud Ribbonwith theSpring Cloud Hystrix,In addition to providing a powerful feature of both, it also provides a declarativeWebHow the service client is defined

Create a new Spring boot project and name Demo-springcloud-feign-consumer, create a new startup class Feignapplication, by @ enablefeignclients Annotations to turn on Spring Cloud feign feature support

definition Yhqservice interface, bind the service by specifying the service name demo-springcloud-client @FeignClient annotations , and then use spring MVC To bind the rest interface provided by the service provider.

Project critical dependencies and configuration spring-cloud-starter-feign provide feign support

Start the registry, start service providers 1 and 2, start feign consumer demo-springcloud-feign-consumer, browser access Http://localhost:3332/feignConsumer

Below we add an interface with parameters for service providers 1 and 2 Helloparam return the string "helloparam1+ parameter" or " helloparam2+ parameter "

In the feign interface Yhqservice binding Helloparam interface, note that the @requestparam here cannot be omitted

Browser Access Http://localhost:3332/feignConsumerParam?name=test Validation results

Dry food sharing microservices Spring-cloud (5. Declarative service call feign)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.