Spring Boot Flashcards

1
Q

What is Spring boot?

A

Sprint boot is a Java-based spring framework used for Rapid Application Development (to build stand-alone microservices). It has extra support of auto-configuration and embedded application server like tomcat, jetty, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are Microservices?

A

Microservices are a software architectural style in which a large application is built as a collection of small, independent services that communicate with each other over a network.

Each service is a self-contained unit of functionality that can be developed, tested, and deployed independently of the other services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the advantages of using Spring Boot?

A

Easy to understand and develop spring applications.

Spring Boot is nothing but an existing framework with the addition of an embedded HTTP server and annotation configuration which makes it easier to understand and faster the process of development.

Increases productivity and reduces development time.

Minimum configuration.

We don’t need to write any XML configuration, only a few annotations are required to do the configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the Spring Boot key components?

A

Spring Boot auto-configuration.
Spring Boot CLI.
Spring Boot starter POMs.
Spring Boot Actuators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why Spring Boot over Spring?

A

Below are some key points which spring boot offers but spring doesn’t:

Starter POM.
Version Management.
Auto Configuration.
Component Scanning.
Embedded server.
InMemory DB.
Actuators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the starter dependency of the Spring boot module?

A

Spring boot provides numbers of starter dependency, here are the most commonly used -

Data JPA starter.
Test Starter.
Security starter.
Web starter.
Mail starter.
Thymeleaf starter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does Spring Boot works?

A

Spring Boot automatically configures your application based on the dependencies you have added to the project by using annotation. The entry point of the spring boot application is the class that contains @SpringBootApplication annotation and the main method.

Spring Boot automatically scans all the components included in the project by using @ComponentScan annotation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the @SpringBootApplication annotation do internally?

A

The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration, and @ComponentScan with their default attributes. Spring Boot enables the developer to use a single annotation instead of using multiple. But, as we know, Spring provided loosely coupled features that we can use for each annotation as per our project needs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does a spring boot application get started?

A

Just like any other Java program, a Spring Boot application must have a main method. This method serves as an entry point, which invokes the SpringApplication#run method to bootstrap the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are starter dependencies?

A

Spring boot starter is a maven template that contains a collection of all the relevant transitive dependencies that are needed to start a particular functionality.
Like we need to import spring-boot-starter-web dependency for creating a web application.
-Located in the POM file
EX: <dependency></dependency>

<groupId> org.springframework.boot</groupId>

<artifactId> spring-boot-starter-web </artifactId>

</dependency>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Spring Boot CLI and what are its benefits?

A

Spring Boot CLI is a command-line interface that allows you to create a spring-based java application using Groovy.

Example: You don’t need to create getter and setter method or access modifier, return statement. If you use the JDBC template, it automatically loads for you.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What Are the Basic Annotations that Spring Boot Offers?

A

The primary annotations that Spring Boot offers reside in its org.springframework.boot.autoconfigure and its sub-packages. Here are a couple of basic ones:

@EnableAutoConfiguration – to make Spring Boot look for auto-configuration beans on its classpath and automatically apply them.

@SpringBootApplication – used to denote the main class of a Boot Application. This annotation combines @Configuration, @EnableAutoConfiguration, and @ComponentScan annotations with their default attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can we create a non-web application in Spring Boot?

A

Yes, we can create a non-web application by removing the web dependencies from the classpath along with changing the way Spring Boot creates the application context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is it possible to change the port of the embedded Tomcat server in Spring Boot?

A

Yes, it is possible. By using the server.port in the application.properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can we override or replace the Embedded tomcat server in Spring Boot?

A

Yes, we can replace the Embedded Tomcat server with any server by using the Starter dependency in the pom.xml file. Like you can use spring-boot-starter-jetty as a dependency for using a jetty server in your project

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Can we disable the default web server in the Spring boot application?

A

Yes, we can use application.properties to configure the web application type i.e spring.main.web-application-type=none.

17
Q

Explain @RestController annotation in Sprint boot?

A

It is a combination of @Controller and @ResponseBody, used for creating a restful controller. It converts the response to JSON or XML. It ensures that data returned by each method will be written straight into the response body instead of returning a template

18
Q

What is the difference between @RestController and @Controller in Spring Boot?

A

@Controller Map of the model object to view or template and make it human readable but @RestController simply returns the object and object data is directly written in HTTP response as JSON or XML

19
Q

Describe the flow of HTTPS requests through the Spring Boot application?

A

Repository Class Extending CRUD Services
Https ^
client <—-> controller <—-> Service layer <—–> Model
request ^ Database ^
JPA/Spring Data

20
Q

What is the difference between RequestMapping and GetMapping?

A

RequestMapping can be used with GET, POST, PUT, and many other request methods using the method attribute on the annotation. Whereas getMapping is only an extension of RequestMapping which helps you to improve on clarity on request

21
Q

What is the use of Profiles in spring boot?

A

While developing the application we deal with multiple environments such as dev, QA, Prod, and each environment requires a different configuration. For eg., we might be using an embedded H2 database for dev but for prod, we might have proprietary Oracle or DB2. Even if DBMS is the same across the environment, the URLs will be different.

22
Q

What is Spring Actuator? What are its advantages?

A

An actuator is an additional feature of Spring that helps you to monitor and manage your application when you push it to production. These actuators include auditing, health, CPU usage, HTTP hits, and metric gathering, and many more that are automatically applied to your application

23
Q

How to enable Actuator in Spring boot application?

A

To enable the spring actuator feature, we need to add the dependency of “spring-boot-starter-actuator” in pom.xml.

<dependency>
<groupId> org.springframework.boot</groupId>
<artifactId> spring-boot-starter-actuator </artifactId>
</dependency>

24
Q

What are the actuator-provided endpoints used for monitoring the Spring boot application?

A

Actuators provide below pre-defined endpoints to monitor our application -

Health
Info
Beans
Mappings
Configprops
Httptrace
Heapdump
Threaddump
Shutdown

25
Q

How to get the list of all the beans in your Spring boot application?

A

Spring Boot actuator “/Beans” is used to get the list of all the spring beans in your application

26
Q

How to check the environment properties in your Spring boot application?

A

Spring Boot actuator “/env” returns the list of all the environment properties of running the spring boot application

27
Q

What is dependency Injection?

A

The process of injecting dependent bean objects into target bean objects is called dependency injection.

Setter Injection: The IOC container will inject the dependent bean object into the target bean object by calling the setter method.

Constructor Injection: The IOC container will inject the dependent bean object into the target bean object by calling the target bean constructor.

Field Injection: The IOC container will inject the dependent bean object into the target bean object by Reflection API

28
Q

What is an IOC container?

A

IoC Container is a framework for implementing automatic dependency injection. It manages object creation and its life-time and also injects dependencies into the class

29
Q

What is a REST API?

A

standardized architecture for building web API’s using HTTP methods.