How can you customize the response status code of a controller method in Spring Boot?
- By returning an instance of ResponseEntity with a custom status code.
- By using the @ResponseStatus annotation with the desired code.
- Modifying the application.properties file with a custom code.
- Configuring the status code in the @GetMapping annotation.
To customize the response status code of a controller method in Spring Boot, you can return an instance of ResponseEntity with a custom status code. This allows fine-grained control over the response, including status codes, headers, and response bodies. The @ResponseStatus annotation is used to declare the default status code for the entire controller class, not for individual methods. The other options are not standard ways to customize the status code.
Loading...
Related Quiz
- In a Spring Boot application, the _____ is a test utility used for making HTTP requests to the application and can be auto-configured in integration tests.
- In a Spring Boot application, you are required to develop a feature where the response body should be customized based on the client's preference. How would you implement this feature using Spring Boot annotations?
- In connection pooling, what does the term "Maximum Pool Size" refer to?
- When creating a custom error response in Spring Boot, the _____ method of the ResponseEntity class can be used to set the HTTP status code of the response.
- In a Spring Cloud environment, to configure a service to discover its peers using Eureka, the property ____ must be defined in the application's properties or YAML file.