In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Feign is a declarative WebService client. Using Feign makes it easier to write WebService clients by defining an interface and then adding annotations to the interface, as well as supporting JAX-RS standard annotations. Feign also supports pluggable encoders and × ×. SpringCloud encapsulates Feign to support SpringMVC standard annotations and HttpMessageConverters. Feign can be used in combination with Eureka and Ribbon to support load balancing.
How to use Feign?
Add dependencies for Feign
Org.springframework.cloud
Spring-cloud-starter-feign
Org.springframework.cloud
Spring-cloud-starter-eureka
Launch the portal to join:
@ SpringBootApplication
@ EnableEurekaClient
@ EnableFeignClients
Finally, don't forget the most important one. I never thought of that. Don't forget. Hehe
Org.springframework.cloud
Spring-cloud-dependencies
Dalston.SR3
Pom
Import
Add annotations and request services to the defined interface: @ FeignClient (name= "name of service")
API method join request method: @ RequestMapping (method = RequestMethod.GET, value = "/ hello")
As for service, there is basically nothing special. The best thing is the client side.
Service just put in @ RestController and @ RequestMapping and can
The stores attribute in the @ FeignClient annotation can be an arbitrary string, and if combined with Eureka, stores should be the service name in Eureka, which Feign uses to create an Ribbon load balancer. You can also specify an address through the url attribute, either the full URL or a hostname. The @ FeignClient annotated interface is marked, and the Bean instance name in ApplicationContext is the fully qualified name of this interface, and the Bean also has an alias, Bean name + FeignClient.
Override the default configuration of Feign
A core concept in SpringCloud's encapsulation of Feign is that the client should have a name. Each client can make a request to a remote service at any time, and each service can specify a name as if it were the @ FeignClient annotation. SpringCloud combines all the @ FeignClient together to create a new ApplicationContext and uses FeignClinetsConfiguration to configure Clients. The configuration includes an encoder, a × ×, and a feign.Contract.
SpringCloud allows you to fully control the configuration information of Feign through the configuration attribute, which has higher priority than FeignClientsConfiguration.
In this way, a basic feign project is completed.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.