WebClient vs RestTemplate

后端 未结 4 1711
青春惊慌失措
青春惊慌失措 2021-01-30 10:45

As per spring 5:

WebClient is an interface representing the main entry point for performing web requests.

It has been created as a part of the Spring

4条回答
  •  半阙折子戏
    2021-01-30 11:16

    No, RestTemplate will continue to exist(atleast for now). You don't have to replace it with WebClient.
    One of the main difference is RestTemplate is synchronous and blocking. i.e when you do a rest call you need to wait till the response comes back to proceed further.

    But WebClient is complete opposite of this. The caller need not wait till response comes back. Instead he will be notified when there is a response.

    If you need such a functionality, then yes you need to replace your Resttemplate with WebClient.
    You can infact achieve Rest template like synchronous processing in webclient using .block(). But the other way is not possible.

    EDIT:

    The RestTemplate will be deprecated in a future version(> 5.0) and will not have major new features added going forward

提交回复
热议问题