Spring Boot, a sub-project of the Spring framework, has gained tremendous popularity among Java developers. Its primary strength lies in simplifying the creation and deployment of Spring applications by removing much of the boilerplate configuration. If you're new to Spring Boot, this set of Multiple Choice Questions (MCQs) offers a gentle introduction and a way to test your foundational knowledge.
1. What is the primary purpose of Spring Boot?
Answer:
Explanation:
While Spring Boot can be used in various contexts like microservice development, its chief aim is to streamline the configuration and deployment of Spring applications.
2. Which embedded server does Spring Boot provide by default for web applications?
Answer:
Explanation:
Spring Boot offers an embedded Apache Tomcat server out of the box, allowing web applications to be easily run without external server setups.
3. What role do "starters" play in Spring Boot?
Answer:
Explanation:
Starters in Spring Boot are templates that furnish a set of default dependencies, easing dependency management for common tasks.
4. Which file format cannot be used to configure properties in Spring Boot?
Answer:
Explanation:
Spring Boot primarily supports .properties and .yml (YAML) for externalized configuration. Traditional XML can be used in certain contexts but not for the main application properties.
5. Which annotation activates Spring Boot's auto-configuration?
Answer:
Explanation:
The @SpringBootApplication annotation encompasses several annotations, including @EnableAutoConfiguration, which activates Spring Boot’s auto-configuration feature.
6. How does Spring Boot decide whether to autoconfigure a specific feature?
Answer:
Explanation:
Spring Boot autoconfiguration is driven by the presence or absence of specific classes in the classpath, among other conditions.
7. What does Actuator in Spring Boot provide?
Answer:
Explanation:
The Spring Boot Actuator provides a range of production-ready features such as monitoring, metrics, and even custom endpoints, making it easier to monitor and manage applications.
8. To externalize Spring Boot's configuration, where can properties be specified?
Answer:
Explanation:
Spring Boot looks for external configurations in an application.properties file by default.
9. What is the purpose of spring-boot-starter-parent?
Answer:
Explanation:
spring-boot-starter-parent provides default configurations, dependency management, and other useful settings for Maven-based Spring Boot projects.
10. How can you specify a specific port number for your Spring Boot application?
Answer:
Explanation:
The port number for a Spring Boot application can easily be specified using the server.port property in the application.properties file.
11. What is the primary advantage of using Spring Boot?
Answer:
Explanation:
While Spring Boot has various benefits, its primary advantage is the acceleration of application development processes with minimal configuration.
12. How does Spring Boot simplify database configurations?
Answer:
Explanation:
Spring Boot uses convention over configuration, which means it provides sensible defaults (e.g., default data source URLs and drivers) but allows them to be overridden if needed.
13. If you want to override Spring Boot's default configurations, which file should you modify?
Answer:
Explanation:
Spring Boot allows users to override its default configurations using the application.properties or application.yml file.
14. Which of these is a benefit of using Spring Boot?
Answer:
Explanation:
Spring Boot simplifies application development by reducing boilerplate code, automating configurations, and providing sensible defaults. However, it doesn't eliminate the need for code or guarantee bug-free applications.
15. What is the primary purpose of @SpringBootApplication annotation?
Answer:
Explanation:
@SpringBootApplication is a convenience annotation that includes @Configuration, @EnableAutoConfiguration, and @ComponentScan.
16. Which annotation is specifically used to indicate that a class provides Bean definitions?
Answer:
Explanation:
The @Configuration annotation indicates that a class declares one or more @Bean methods which will be processed by the Spring container.
17. What is the primary function of @Conditional annotation in Spring Boot?
Answer:
Explanation:
@Conditional is used to indicate a condition that, when met, enables the configuration or component.
18. Which Spring annotation is used to create RESTful web services using Spring MVC?
Answer:
Explanation:
When you annotate a class with @RestController, it indicates that the class is a Spring MVC REST controller responsible for handling incoming HTTP requests and generating the appropriate HTTP responses.
19. Which Spring annotation is used to handle HTTP POST requests?
Answer:
Explanation:
The @PostMapping annotation is used to map an HTTP POST request to a specific handler method in a Spring MVC controller. It is a shortcut for specifying the @RequestMapping annotation with the RequestMethod.POST method.
20. Which starter dependency is used to develop web applications or Restful web services?
Answer:
Explanation:
The spring-boot-starter-web dependency provides the necessary components to develop Web Applications and RESTful API in a Spring Boot project, including the embedded Tomcat server, Spring Web MVC, and other required dependencies.