SpringBoot 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

Features of Spring Boot that make it different?

A
  • Creates stand-alone spring application with minimal configuration needed.
  • It has embedded tomcat, jetty which makes it just code and run the application.
  • Provide production-ready features such as metrics, health checks, and externalized configuration.
  • Absolutely no requirement for XML configuration.
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
  • 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
  • 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

What is the purpose of using @ComponentScan in the class files?

A

Spring Boot application scans all the beans and package declarations when the application initializes. You need to add the @ComponentScan annotation for your class file to scan your components added to your project.

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

What are the most common Spring Boot CLI commands?

A

-run, -test, -grap, -jar, -war, -install, -uninstall, –init, -shell, -help.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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
12
Q

What is Spring Boot dependency management?

A

Spring Boot dependency management is used to manage dependencies and configuration automatically without you specifying the version for any of that dependencies.

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

How to disable a specific auto-configuration class?

A

You can use exclude attribute of @EnableAutoConfiguration if you want auto-configuration not to apply to any specific class.

//use of exclude
@EnableAutoConfiguration(exclude={className})
18
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.

19
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.

20
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.

21
Q

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

A
  • Health
  • Info
  • Beans
  • Mappings
  • Configprops
  • Httptrace
  • Heapdump
  • Threaddump
  • Shutdown
22
Q

Where do we define properties in the Spring Boot application?

A

You can define both application and Spring boot-related properties into a file called application.properties. You can create this file manually or use Spring Initializer to create this file. You don’t need to do any special configuration to instruct Spring Boot to load this file, If it exists in classpath then spring boot automatically loads it and configure itself and the application code accordingly.

23
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.
24
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.