InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Define HttpMessageConverter in terms of Spring REST? |
|
Answer» HttpMessageConverter is a strategic INTERFACE that specified a converter for conversion between HTTP Requests and responses. Spring REST uses the HttpMessageConverter for converting responses to various data formats like JSON, XML, etc. Spring makes use of the “Accept” header for determining the TYPE of content the client expects. Based on this, Spring would FIND the registered MESSAGE converter interface that is CAPABLE of this conversion. |
|
| 2. |
Is it necessary to keep Spring MVC in the classpath for developing RESTful web services? |
|
Answer» YES. Spring MVC needs to be on the classpath of the application while developing RESTful web services using Spring. This is because, the Spring MVC provides the necessary annotations like @RestController, @RequestBody, @PATHVARIABLE, etc. HENCE the spring-mvc.jar needs to be on the classpath or the CORRESPONDING Maven entry in the pom.xml. |
|
| 3. |
What does the annotation @PathVariable do? |
|
Answer» @PathVariable ANNOTATION is used for passing the parameter with the URL that is required to get the data. SPRING MVC PROVIDES support for URL customization for data retrieval using @PathVariable annotation. |
|
| 4. |
What are the differences between the annotations @Controller and @RestController? |
||||||||||
Answer»
|
|||||||||||
| 5. |
What is the use of @RequestMapping? |
Answer»
|
|
| 6. |
Define RestTemplate in Spring. |
|
Answer» The RestTemplate is the MAIN class meant for the client-side access for Spring-based RESTful services. The communication to the server is accomplished using the REST CONSTRAINTS. This is similar to other template classes such as JdbcTemplate, HibernateTemplate, etc provided by Spring. The RestTemplate provides high-level implementation details for the HTTP Methods like GET, POST, PUT, etc, and gives the methods to communicate using the URI template, URI path params, request/response types, request object, etc as PART of arguments.
|
|