Spring Boot for Microservices: Communication

In this lesson, we'll look at how Spring Boot fulfills the communication requirement.

The suitability of Spring Boot for the implementation of microservices can be decided according to the criteria of this lesson of this chapter.

Communication #

For communication, Spring Boot supports REST, the previous listing shows. The listing uses the Spring MVC API.

                                                T H E  S P R I N G   M V C   A P I        

The Spring MVC framework resides pretty well with REST and provides the necessary API support to implement it seamlessly, with little effort.

The importance of SpringMVC in RESTful web services #

I. In Spring MVC, a controller handles requests for all the HTTP methods. This serves as a backbone for RESTful web services.


  • GET methods can be used to handle read operations
  • POST methods can be used to create new resources
  • PUT methods can be used to update resources
  • DELETE methods can be used to remove resources from the server

II. The representation of data is crucial in REST. This is why Spring MVC allows us to evade View-based rendering completely by the use of @ResponseBody annotation and many HttpMessageConverter implementations. By this, a response can be sent directly to a client.

III. Spring version 4.0’s @RestController added in the controller class applies message conversations to all handler methods in the controller, preventing the need to annotate each method with the @ResponseBody annotation. This also makes our code much cleaner.

IV. Spring MVC also provides @RequestBody annotation, which uses HttpMethodConverter implementations to convert inbound HTTP data into Java objects passed into a controller’s handler method.

V. The Spring framework also provides a template class, the RestTemplate, which can consume REST resources. You can use this class to test your RESTful web service or develop REST clients.

These were some of the important features of the Spring MVC framework which assist in developing RESTful web services.

Get hands-on with 1200+ tech skills courses.