Spring Boot Interview Questions and Answers
Spring Boot Interview Questions and Answers
There are many useful features of Spring Boot. Some of them are mentioned
below:
Here is a table that summarizes why we use Spring Boot over Spring
framework.
Here are the main steps involved in how Spring Boot works:
Spring Boot provides many starter dependencies. Some of them which are
used the most in the Spring Boot application are listed below:
Example:
Java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MyApplication
{
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
11. What are Spring Boot CLI and the most used CLI commands?
Spring Boot CLI is a command-line tool that can be used to create, run, and
manage Spring Boot applications. It is a powerful tool that can help us to get
started with Spring Boot quickly and easily. It is built on top of the Groovy
programming language.
● -run
● -test
● -jar
● -war
● –init
● -help
Spring Boot Intermediate Interview Questions
To create a web application, we can add the S pring Boot starter web
dependency to our application.
The simple way is to set the server. port property in your application’s
application.properties file. For example, to set the port to 8081, add the
following property to the application.properties file:
server.port=8081
● Dependencies
● Version control
● Configuration needed to make certain features.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
To know more about Spring Boot Starters, refer to this article – Spring
Boot – Starters
The default port of the embedded Tomcat server in Spring Boot is 8080 . We
can change the default port by setting the server.port property in your
application’s application.properties file.
17. Can we disable the default web server in the Spring Boot
application?
Yes, we can disable the default web server in the Spring Boot application. To
do this, we need to set the server.port property to “-1” in the application’s
application.properties file.
@EnableAutoConfiguration(exclude = {//classname})
20. Describe the flow of HTTPS requests through the Spring Boot
application.
Used with
@RequestMapping Used to handle
Request handling
annotation to map requests like GET, PUT,
and Mapping
HTTP requests with POST, and DELETE.
methods.
@RequestMapping(valu
@GetMapping(“/example”
Example e = “/example”, method
)
= RequestMethod.GET)
@EnableAutoConfigurati
Features @SpringBootApplication
on
When to When we want to customize
When we want to use auto-configuration
use auto-configuration
Compone
Includes @ComponentScan annotation Does not perform component
nt
to enable component scanning. scanning by itself.
Scanning
Spring Profiles are like different scenarios for the application depending on
the environment.
● You define sets of configurations (like database URLs) for different
situations (development, testing, production).
● Use the @Profile annotation to clarify which config belongs to
where.
● Activate profiles with environment variables or command-line
options.
Embedded
Feature WAR
containers
● Without arguments
● With basePackageClasses
● With basePackages
31. How to get the list of all the beans in your Spring boot
application?
Yes, we can check the environment properties in our Spring Boot Application.
The Environment object in a Spring Boot application can be used to check the
environment’s properties.
● property files
● command-line arguments
● environment variables
To enable debugging log in Spring Boot Application, follow the below steps:
Using the actuator endpoint, the log level can also be changed at runtime.
Curl -X POST
\http://localhost:8080/actuator/loggers/<logger-name>
To know more about IOC Container, refer to the article – Spring – IoC
Container
36. What is the difference between Constructor and Setter
Injection?
Constructor
Features Setter Injection
Injection
● Spring Data JPA: This project provides support for accessing data
from relational databases using JPA.
MVC stands for Model, View, and Controller. Spring MVC is a web MVC
framework built on top of the Spring Framework. It provides a comprehensive
programming model for building web applications.
An Inner Bean refers to a bean that is defined within the scope of another
bean’s definition. It is a way to declare a bean inside the configuration of
another bean, without explicitly giving it a unique identifier.
● Autowiring
● Manual wiring
To know more about Spring Boot DevTools, refer to the article – Spring
Boot – DevTools
java.lang.ClassNotFoundException: org.h2.Driver
To know more, refer to this article – Spring Boot – CRUD Operations using
MySQL Database
10. Mention the advantages of the YAML file over than Properties
file and the different ways to load the YAML file in Spring boot.
To know more about Spring Data REST, Please Refer to this article-
Spring – REST Controller
Here are the reasons why not to choose Spring Data REST:
● Performance – Performance may not be optimal for very large-scale
applications.
● Versioning – It can be difficult to version the REST APIs exposed by
Spring Data REST.
● Relationships – Handling relationships between entities can be
tricky with Spring Data REST.
● Filtering – There are limited options for filtering the results returned
by the endpoints.
● Hibernate Architecture
● Java – JPA vs Hibernate
Below are the steps on how to deploy to a different server with Spring Boot: