Summary of frequently asked questions about feign in spring cloud
1、 Feignclient interface, cannot use composite annotations such as @ gettingmapping
Code example:
The @ requestmapping (value = "/ simple / {ID}", method = requestmethod. Get) here cannot be written as @ getmapping ("/ simple / {ID}").
2、 In feignclient interface, if @ pathvariable is used, its value must be specified
Code example:
The "Id" in the @ pathvariable ("Id") here cannot be omitted and must be specified.
3、 Construction of feignclient multi parameter
If you want to request the microservice provider user service, and there are multiple parameters, for example: http://microservice-provider-user/query-by?id=1&username= What should Zhang San do?
Use complex objects directly:
The request will not succeed. As long as the parameter is a complex object, feign will still send the request in the post method even if the get method is specified.
Correct writing:
Writing 1:
Writing 2:
4、 Feign needs to do some additional operations if he wants to use hystrix stream
We know that feign itself supports hystrix. You can directly use @ feignclient (value = "microservice provider user", fallback = XXX. Class) to specify the fallback class. This fallback class can integrate the interface marked by @ feignclient.
However, suppose we need to use hystrix stream for monitoring. By default, access http://IP:PORT/hystrix.stream It's a 404. How to add hystrix stream support to feign?
The following two steps are required:
Step 1: add dependency. Example:
Step 2: add @ enablercircuitbreaker annotation on the startup class. Example:
After this modification, access any API before accessing http://IP:PORT/hystrix.stream , a lot of API monitoring data will be displayed.
5、 If you need to customize a single feign configuration, the class of the @ configuration annotation of feign cannot overlap with the package of @ componentscan
If the packages overlap, all feign clients will use this configuration.
6、 First request failed
See: how to solve feign / ribbon's first request failure in spring cloud