A summary of Feign FAQ in Spring Cloud.
FeignClient interface. Combined annotations such as @gettingMapping cannot be used
Code examples:
@requestMapping (value = “/simple/{id}”, method = requestmethod.get) cannot be @getMapping (“/simple/{id}”).
In the FeignClient interface, if @PathVariable is used, its value must be specified
Code examples:
The “ID” in @PathVariable(“id”) cannot be omitted, it must be specified.
FeignClient multi-parameter construction
If you want to request the microservice-provider-user service with multiple parameters, for example, http://microservice-provider-user/query-by? If id=1 and username= 1
Using complex objects directly:
The request will not succeed, as long as the parameters are complex objects, feign will still send the request as POST even if GET is specified.
Correct way to write it:
Method 1:
Method 2:
Feign needs to do something extra if it wants to use Hystrix Stream
@feignClient (value = “microservice-provider-user”, fallback = xxx. class); This fallback class integrates the interface annotated by @FeignClient.
But suppose we need to use Hystrix Stream monitor, by default, http://IP:PORT/hystrix.stream is a 404. How do you add Hystrix Stream support to Feign?
The following two steps are required:
Step 1: Add a dependency. Example:
Step 2: Add the @enablecircuitbreaker annotation to the startup class, as in:
After such modifications, following a visit to any API, visit http://IP:PORT/hystrix.stream again, will show a lot of API monitoring data.
If you need to customize a single Feign Configuration, Feign’s @Configuration annotation class cannot overlap with the @ComponentScan package
If packages overlap, this will cause all Feign Clients to use this configuration.
First request failed
Note the @feignClient property
(1) The serviceId attribute is invalid. Try to use the name attribute. Such as:
It is not recommended to write:
(2) When using URL attributes, in the old version of Spring Cloud, there is no need to provide the name attribute, but in the new version (such as Brixton, Camden) @feignClient must provide the name attribute, and the name and URL attributes support placeholders. Such as:
Welcome everyone to join me in learning spring Cloud to build micro-service cloud architecture. I will record the construction process and essence of the recently developed Spring Cloud micro-service cloud architecture to help more friends who are interested in developing spring Cloud framework. Discuss the process of building the Spring Cloud architecture and how it can be applied to enterprise projects.
I personally invite all BATJ architecture masters to create Spring Cloud to build an exchange community of micro-service architecture. (Group number: 547793198) Welcome architects and developers to learn and exchange practical experience in using Spring Cloud’s many powerful components.
The reason why someone is always better than you is because they are already better and are constantly trying to become better, while you are still satisfied with the status quo and secretly happy!
Rational use of their every minute every second of time to learn to improve themselves, do not use “no time” to cover up their ideological laziness! While young, hard to fight, to the future of their own account!
Hope this article can help you at the same time, also listen to your point of view. Welcome to comment, add attention, share your ideas! Keep updating!
- To-morin Java architecture
Share the latest Internet articles to pay attention to the latest development of the Internet