Spring Boot Flashcards
What is Spring Boot?
Spring Boot is a framework designed to simplify the bootstrapping and development of a new Spring application. The framework takes an opinionated approach to configuration, freeing developers from the need to define boilerplate configuration.
What is the advantage of using Spring Boot?
The advantage of using Spring Boot is that it simplifies Spring application setup and development. It has auto-configuration features for Spring and third party libraries, allowing developers to start quickly. It reduces the amount of manual configuration and code, and it has embedded Tomcat, Jetty, or Undertow, so you don’t need to deploy WAR files.
What are the key components of Spring Boot?
Key components of Spring Boot are: Spring Boot Starters, Spring Boot AutoConfigurator, Spring Boot Actuator, Spring Boot CLI, and Spring Initializr.
What is the difference between Spring and Spring Boot?
Spring is a comprehensive framework for building enterprise-grade applications, while Spring Boot is a way to simplify the configuration for Spring applications, aiming to be a rapid application development platform. Spring Boot uses the Spring framework underneath.
What is the Spring Initializer?
Spring Initializr is a web-based tool provided by Spring, allowing you to generate the basic project structure for your Spring Boot application.
What is the purpose of the @SpringBootApplication annotation?
The @SpringBootApplication annotation is used to mark a configuration class that declares one or more @Bean methods and triggers auto-configuration and component scanning.
What is the difference between @Configuration and @SpringBootConfiguration?
@Configuration is used to mark a class as a source of bean definitions. On the other hand, @SpringBootConfiguration is a specialized form of @Configuration that indicates a configuration class specifically for Spring Boot application.
What is the difference between @Component and @Service?
Both @Component and @Service are used to denote a class as a Spring Bean. However, @Service is used in the service layer, and @Component can be used in any layer (it’s a more generic annotation).
What is the purpose of the @Autowired annotation?
The @Autowired annotation is used to auto-wire spring bean on setter methods, instance variable, and constructor.
What is the difference between @ComponentScan and @SpringBootApplication?
Both @ComponentScan and @SpringBootApplication serve a similar purpose, which is to tell Spring where to search for components. However, @SpringBootApplication is more specific to Spring Boot applications and it also implies @EnableAutoConfiguration and @Configuration.
What is the purpose of the @Bean annotation?
The @Bean annotation is used at the method level and it tells Spring that the method will return an object that should be registered as a bean in the Spring application context.
What is the purpose of the @Value annotation?
The @Value annotation is used at the field level or method parameter level and it indicates a default value for the field or parameter.
What is the difference between @Controller and @RestController in Spring Boot?
The @Controller annotation is used to define a controller in a traditional Spring MVC application. The @RestController annotation is a specialized version of the controller, designed to simplify creating RESTful web services. It includes the @ResponseBody annotation which binds the return value directly to the response body.
What is the difference between @Repository and @Service in Spring Boot?
The @Repository annotation is used on the persistence layer of the application, which indicates that the class provides the mechanism for storage, retrieval, search, update, and delete operation on objects. The @Service annotation is used at the service layer, which holds business logic.
What is the purpose of the @Primary annotation in Spring Boot?
The @Primary annotation in Spring Boot is used when you have more than one bean of the same type and you want to give one of them higher priority.