Book Image

Mockito for Spring

By : Sujoy Acharya
Book Image

Mockito for Spring

By: Sujoy Acharya

Overview of this book

Table of Contents (12 chapters)
Mockito for Spring
About the Author
About the Reviewers

Exploring @RestController

JAX-RS provides the functionality for Representational State Transfer (RESTful) web services. REST is well-suited for basic, ad hoc integration scenarios. Spring MVC offers controllers to create RESTful web services.

In Spring MVC 3.0, we need to explicitly annotate a class with the @Controller annotation in order to specify a controller servlet and annotate each and every method with @ResponseBody to serve JSON, XML, or a custom media type. With the advent of the Spring 4.0 @RestController stereotype annotation, we can combine @ResponseBody and @Controller.

The following example will demonstrate the usage of @RestController:

  1. Create a dynamic web project, RESTfulWeb.

  2. Modify the web.xml file and add a configuration to intercept requests with a Spring DispatcherServlet:

    <web-app xmlns:xsi="" xmlns="" xmlns:web="" xsi:schemaLocation="http://java...