Representational State Transfer (REST) has taken the software industry by storm, becoming the standard architecture for building web services. With Spring Boot's power and ease of development, building RESTful APIs has never been easier. For beginners stepping into this realm, understanding the fundamentals and quirks of Spring Boot's REST support is essential. Test your foundational knowledge with this set of MCQs!
1. What does REST stand for?
Answer:
Explanation:
REST stands for Representational State Transfer, a standard architecture for building web services.
2. Which annotation is used to create a RESTful controller in Spring Boot?
Answer:
Explanation:
The @RestController annotation in Spring Boot is used to mark a class as a RESTful web service controller.
3. How can you specify the HTTP method for an endpoint in Spring Boot?
Answer:
Explanation:
Spring Boot provides annotations like @GetMapping, @PostMapping, @PutMapping, etc., to specify the HTTP method for an endpoint.
4. Which annotation is used to capture a path variable from a URL in Spring Boot?
Answer:
Explanation:
The @PathVariable annotation is used to capture a variable from the URI path.
5. Which of the following is the default embedded servlet container for Spring Boot?
Answer:
Explanation:
Tomcat is the default embedded servlet container for Spring Boot.
6. How do you define properties in Spring Boot?
Answer:
Explanation:
In Spring Boot, properties can be defined using .properties or .yml files.
7. How can you specify a different context path for your Spring Boot application?
Answer:
Explanation:
The server.servlet.context-path property in Spring Boot is used to set a different context path.
8. Which annotation in Spring Boot is used to bind the properties in a properties file to a POJO?
Answer:
Explanation:
The @ConfigurationProperties annotation binds properties to a POJO.
9. What is the primary role of the @SpringBootApplication annotation in Spring Boot?
Answer:
Explanation:
The @SpringBootApplication annotation is a convenience annotation that includes @Configuration, @EnableAutoConfiguration, and @ComponentScan.
10. How can you externalize configuration in Spring Boot for different environments?
Answer:
Explanation:
Spring Boot allows externalized configuration using multiple properties files (like application-dev.properties, application-prod.properties) and also with the use of @Profile annotation.
11. In Spring Boot, how can you specify that a method parameter should be bound to a web request body?
Answer:
Explanation:
The @RequestBody annotation in Spring Boot is used to indicate that a method parameter should be bound to the body of the web request.
12. What does the @ResponseStatus annotation do?
Answer:
Explanation:
The @ResponseStatus annotation can be used on a method or exception class to define the HTTP status that should be returned.
13. Which of the following can be used to enable Cross-Origin Resource Sharing (CORS) globally in a Spring Boot application?
Answer:
Explanation:
For global CORS configuration, a bean that implements WebMvcConfigurer and overrides addCorsMappings(CorsRegistry registry) can be used.
14. Which annotation is used to handle exceptions in Spring Boot RESTful services?
Answer:
Explanation:
While @ExceptionHandler is used for handling exceptions within a single controller, @ControllerAdvice can be used to handle exceptions across multiple controllers.
15. Which of the following helps in versioning of a REST API in Spring Boot?
Answer:
Explanation:
All the mentioned techniques can be used for versioning a REST API in Spring Boot. The choice depends on the specific use-case and requirements.
16. Which of the following is NOT an HTTP method?
Answer:
Explanation:
SET is not a standard HTTP method. The standard methods include GET, POST, PUT, DELETE, etc.
17. Which annotation can be used to inject values from application.properties directly into a field?
Answer:
Explanation:
The @Value annotation is used to inject values from property files into fields in Spring Boot.
18. Which of the following is a blocking paradigm?
Answer:
Explanation:
Servlet is a blocking paradigm, while WebFlux, Reactor, and RxJava are non-blocking and often associated with reactive programming.
19. Which Spring Boot starter dependency is typically added for building RESTful web services?
Answer:
Explanation:
For building RESTful web services, spring-boot-starter-web is typically added as a dependency.
20. Which of the following is used to customize the default behavior of Spring Boot auto-configuration?
Answer:
Explanation:
While @Configuration is used to declare a class as a source of bean definitions, the @Bean annotation indicates that a method produces a bean to be managed by the Spring container, allowing customization of auto-configured beans.
Comments
Post a Comment