SpringBootQuestions Flashcards
What is Spring?
Spring is a powerful, open-source, lightweight, loose coupled, framework meant to reduce the complexity of developing applications.
Spring handles all the structure-related aspects which allow the developer to focus mostly on application development.
Some of the features of Spring are:
- Inversion of Control:
- Creating and Managing: the lifecycle of the applications objects
- Highly Configurable: Allows switching frameworks
What is Spring Boot?
Spring Boot is an open-source, java-based framework that provides an easier and faster way to set up, configure and run production-ready Spring applications with a need for very few configurations.
Spring vs Spring Boot
The difference between Spring and Spring Boot is
- Spring, is a widely used Java framework that helps develop loosely coupled applications.
- The most commonly used features of the Spring framework are Dependency Injection, however, it does offer many other features, like the container, which creates and manages the lifecycle of the beans, meaning the objects and many others.
- With Spring, the developer has to manually define dependencies for the project in the pom file.
The Sprint Boot Framework:
- internally takes care of downloading the dependencies JARs based on Spring Boot Requirements,
- which helps to create applications with less configuration.
- Spring Boot’s primary feature is auto-configuration
Mentioned some features of Spring Boot
Auto-Configuration - Starter Dependency - Spring Initializer - Easily builds the structure of the project Spring Actuator - Logging & Security Spring CLI
Spring Boot
Describe the feature Starter Dependency
Starter Dependency – With the help of this feature, Spring Boot bundles common dependencies together and eventually improves productivity and reduces the burden on having to look through code to find the dependencies needed for the project.
Some of the most used starter dependencies are;
- spring-boot-starter-parent
- spring-boot-starter-web
- spring-boot-starter-test
Spring Boot
Describe the Spring Initializer feature
The Spring Initializer helps the developer to easily create the internal project structure so that the developer doesn’t have to manually set up the structure of the project.
With this feature, the developer can add mostly used dependencies, such as Spring Web, Thymeleaf, and Spring Boot DevTools.
SpringBoot
Describe the feature of Auto-Configuration
The Auto-configuration automatically configures the Spring application based on the jar dependencies that the developer added to the pom file.
For example, if the H2 database Jar is present in the classpath and we have not configured any beans related to the database manually, the Spring Boot’s auto-configuration feature automatically configures it in the project.
What is the @SpringBootApplication annotation?
The @SpringBootApplication annotation is used in the main class and is a combination of the
@Configuration
@ComponentScan
and
@EnableAutoConfiguration
What is the @EnableAutoConfiguration annotation?
The @EnableAutoConfiguration annotation auto-configures the beans that are present in the classpath and scans for components.
It’s a combination of the:
@Configuration
@ComponentScan
What do you mean by IoC (Inversion of Control) Container?
Inversion of Control transfers the control of an object to a container.
Some of the advantages are:
- Decoupling the execution of a task from the implementation
- Making it easier to test a program by mocking its dependencies
Spring container is the most important part of the Spring Framework.
The Spring container uses Dependency Injection (DI) for managing the application components by creating objects known as beans, configuring them, and managing their life cycles.
The instructions for the spring container to do the tasks can be provided either by Java annotations, or Java code.
What are the Spring Boot starters?
Spring Boot starters are dependency management providers that can be included in the application pom file.
These starters, make development easier and avoids developers having to go through sample code for commonly used dependencies.
A couple of Spring Boot starters are:
- spring-boot-starter-parent: Provides Java version, dependency, and plugin management for applications built with Maven
- spring-boot-starter-web: Starter for building web applications, including RESTful applications using Spring MVC. Uses Tomcat as the embedded server.
- spring-boot-starter-test - It’s used to test Spring Boot applications with libraries, including, JUnit, and Mockito
What is the difference between @Controller and @RestController?
The @Controller is a specialization annotation of the Component class.
The @RestController is a special version of the @Controller. It combines @Controller and @ResponseBody and simplifies the controller implementation.
Therefore, the @ResponseBody is not required.
How does the @ResponseBody annotation works
The @Response annotation enables serialization of the object into the HttpResponse
Why should we use Spring Booth?
We should use Spring Boot because:
- Because the dependency injection approach is used in Java
- It simplifies the integration of other Java frameworks like JPA
- It reduces the cost and development time of the application
Advantages of Spring Boot
- Creates stand-alone Spring applications
- It provides starter dependencies
- Provides production-ready features such as metrics, and health check
- Reduces having to write boilerplate code
What are Spring Boot limitations
The only one I know is that it can use dependencies that are not going to be used in the application. These dependencies increase the size of the application.