Feign of spring cloud

Take my personal blog system as an example to request other microservice APIs.

1、 Add Maven dependency

2、 Add @ enablefeignclients to the startup class

3、 Writing service interface classes

Special attention:

@Feignclient ("blog API"), where the blog API must be a service instance registered with Eureka server.

The corresponding request type of @ requestmapping must be written accurately. For get requests, write get, and for post requests, write post. This is one of them.

In addition, whether the request parameter is in the form of address bar or request body must also be clearly written (remember that it must be consistent with the corresponding microservice URL, otherwise the request will have problems). This is the second reason to write it clearly in the form of @ requestparam or @ requestbody or @ pathvariable.

4、 Write controller

5、 Testing

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>