Spring Boot Interview Questions for Freshers
Spring Boot Interview Questions for Freshers
Spring Boot is built on top of the Spring framework to create stand-alone RESTful web applications
with very minimal configuration and there is no need of external servers to run the application
because it has embedded servers like Tomcat and Jetty etc.
To know more about Spring Boot, refer to this article – Introduction to Spring Boot
There are many useful features of Spring Boot. Some of them are mentioned below:
• Spring Boot Starter POM – These Starter POMs are pre-configured dependencies for
functions like database, security, maven configuration etc.
• Spring Boot CLI (Command Line Interface) – This command line tool is generally for
managing dependencies, creating projects and running the applications.
• Actuator – Spring Boot Actuator provides health check, metrics and monitors the endpoints
of the application. It also simplifies the troubleshooting management.
• Embedded Servers – Spring Boot contains embedded servers like Tomcat and Jetty for quick
application run. No need of external servers.
Spring Boot is a framework that creates stand-alone, production grade Spring based applications. So,
this framework has so many advantages.
• Easy to use: The majority of the boilerplate code required to create a Spring application is
reduced by Spring Boot.
• Scalable: Spring Boot apps are intended to be scalable. This implies they may be simply
scaled up or down to match your application’s needs.
• Production-ready: Metrics, health checks, and externalized configuration are just a few of
the features that Spring Boot includes and are designed for use in production environments.
• Auto-configuration
• Embedded Servers
Here is a table that summarizes why we use Spring Boot over Spring framework.
To know more, refer to the article – Difference between Spring and Spring Boot
Here are the main steps involved in how Spring Boot works:
• Start by creating a new Spring Boot project.
To know more about internal working of spring boot application, refer to this article – How Spring
Boot Application works Internally?
Spring Boot provides many starter dependencies. Some of them which are used the most in the
Spring Boot application are listed below:
• Web starter
• Security starter
• Test Starter
• Thymeleaf starter
• Once the application context is initialized, the run() method starts the application’s
embedded web server.
Example:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
SpringApplication.run(MyApplication.class, args);
• @AutoConfiguration : This annotation automatically configuring beans in the class path and
automatically scans the dependencies according to the application need.
• @Configuration: This annotation configures the beans and packages in the class path.
Spring Initializer is a tool that helps us to create skeleton of spring boot project or project structure
by providing a maven or gradle file to build the application. It set up the framework from scratch.
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
• @Component: This annotation is the most generic annotation for any Spring-managed
component. It is used to mark a class as a Spring bean that will be managed by the Spring
container.
• @RestController: This annotation is used to define a RESTful web service controller. It is a
specialized version of the @Controller annotation that includes the @ResponseBody
annotation by default.
To know more about Spring Boot Annotations, refer to this article – Spring Boot – Annotations
Spring Boot dependency management makes it easier to manage dependencies in a Spring Boot
project. It makes sure that all necessary dependencies are appropriate for the current Spring Boot
version and are compatible with it.
To create a web application, we can add the S pring Boot starter web dependency to our application.
To know more about Spring Boot Dependency Management, refer to this article – Spring Boot –
Dependency Management
14. Is it possible to change the port of the embedded Tomcat server in Spring Boot?
Yes, it is possible to change the port of the embedded Tomcat server in a Spring Boot 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
Spring Boot Starters are a collection of pre-configured maven dependencies that makes it easier to
develop particular types of applications. These starters include,
• Dependencies
• Version control
• Configuration needed to make certain features.
To use a Spring Boot starter dependency , we simply need to add it to our project’s pom.xml file. For
example, to add the Spring Boot starter web dependency, add the following dependency to the
pom.xml file:
<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})
Yes, we can create a non-web application in Spring Boot. Spring Boot is not just for web applications.
Using Spring Boot, we can create applications like Microservices, Console applications, and batch
applications.
20. Describe the flow of HTTPS requests through the Spring Boot application.
• After that the request will go to the controller, where all the requests will be mapped and
handled.
• After this in Service layer, all the business logic will be performed. It performs the business
logic on the data that is mapped to JPA (Java Persistence API) using model classes.
• In repository layer, all the CRUD operations are being done for the REST APIs .
• @Controller : Marks the class as a request handler in the Spring MVC framework.
• @ResponseBody : Tells Spring to convert method return values (objects, data) directly into
HTTP responses instead of rendering views.
It enables us to Define endpoints for different HTTP methods (GET, POST, PUT, DELETE), return data
in various formats (JSON, XML, etc.) and map the request parameters to method arguments.
Note: Both annotations handle requests, but @RestController prioritizes data responses for building
API.
@RequestMapping(value =
“/example”, method = @GetMapping(“/example”)
Example RequestMethod.GET)
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).
To use Spring Profiles, we simply need to define the spring.profiles.active property to specify which
profile we want to use.
Requires external
Uses configuration properties
configuration files (e.g.,
or annotations within the
web.xml, context.xml) to
application code.
Configuration define the web application.
Note: To use Spring Boot Actuator, we simply need to add the spring-boot-starter-actuator
dependency to our project.
To know more about Actuator, refer to this article – Spring Boot Actuator
@ComponentScan annotation is used to tell Spring to scan a package and automatically detect
Spring components, configurations, and services to configure. The @ComponentScan annotation can
be used in the following ways:
• Without arguments
• With basePackageClasses
• With basePackages
To know more about @ComponentScan annotation, refer to this article – Spring @ComponentScan
Annotation with Example
30. What are the @RequestMapping and @RestController annotations in Spring Boot used for?
• URL path
• URL parameters
• Request headers
31. How to get the list of all the beans in your Spring boot application?
• Using the ApplicationContext object in Spring Boot, we can retrieve a list of all the beans in
our application.
• The ApplicationContext is responsible for managing the beans and their dependencies.
32. Can we check the environment properties in your Spring boot application explain how?
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.
Dependency Injection (DI) is a design pattern that enables us to produce loosely coupled
components. In DI, an object’s ability to complete a task depends on another object. There three
types of dependency Injections.
• Constructor injection: This is the most common type of DI in Spring Boot. In constructor
injection, the dependency object is injected into the dependent object’s constructor.
• Setter injection: In setter injection, the dependency object is injected into the dependent
object’s setter method.
• Field injection : In field injection, the dependency object is injected into the dependent
object’s field.
To know more about Dependency Injection, refer to the article – Spring Dependency Injection with
Example – GeeksforGeeks
An IoC (Inversion of Control) Container in Spring Boot is essentially a central manager for the
application objects that controls the creation, configuration, and management of dependency
injection of objects (often referred to as beans), also referred to as a DI (Dependency Injection)
container.
To know more about IOC Container, refer to the article – Spring – IoC Container
1. What is Thymeleaf?
Thymeleaf is a Java-based server-side template engine used in Java web applications to render
dynamic web pages. It is a popular choice for server-side templating in the Spring ecosystem,
including Spring Boot.
To know more about Thymeleaf, refer to this article – Spring Boot – Thymeleaf with Example
Spring Data is a powerful framework that can be used to develop data-oriented applications. It aims
to simplify the development of data-centric applications by offering abstractions, utilities, and
integration with various data sources.
• 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 object that is managed by the Spring IoC container is referred to as a spring bean. A Spring bean
can be any Java object.
5. What are Inner Beans in Spring?
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.
To define an Inner Bean in Spring, we can declare it as a nested <bean> element within the
configuration of the enclosing bean.
Bean wiring is a mechanism in Spring that is used to manage the dependencies between beans. It
allows Spring to inject collaborating beans into each other. There are two types of Bean Wiring:
• Autowiring
• Manual wiring
• Actuator endpoints
To know more about Spring Boot DevTools, refer to the article – Spring Boot – DevTools
java.lang.ClassNotFoundException: org.h2.Driver
9. Mention the steps to connect the Spring Boot application to a database using JDBC.
To connect an external database like MySQL or Oracle to a Spring Boot application using JDBC, we
need to follow below steps:
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.
• Conciseness
Spring Data REST is a framework that exposes Spring Data repositories as RESTful web services. It
allows us to expose repositories as REST endpoints with minimal configuration by following Spring
Data REST Technologies like Spring Data and Spring MVC .
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:
• 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.
13. How is Hibernate chosen as the default implementation for JPA without any configuration?
Spring Boot automatically configures Hibernate as the default JPA implementation when we add
the spring-boot-starter-data-jpa dependency to our project. This dependency includes the Hibernate
JAR file as well as the Spring Boot auto-configuration for JPA.
• Hibernate Architecture
Below are the steps on how to deploy to a different server with Spring Boot:
What will be the Spring Boot Interview Questions for 5 Years Experience?
In the interview, candidates with over 5 years of experience are primarily questioned about these
concepts.
2. Starters : Dependency management artifacts for easy integration of common Spring Boot
features like web apps, data access, and security.
4. Best practices: Use dependency injection, version control, and thorough testing when
developing Spring Boot apps.
6. Improving skills : Enhance Spring Boot skills through documentation, conferences, and
contributing to the project.
• What is the default port of the embedded Tomcat server in Spring Boot?
• How to change the port of the embedded Tomcat server in Spring Boot?
There are a few things you can do to prepare for Spring Boot interview questions:
• Create a Spring Boot project and experiment with the different features
• Join the Spring Boot community on Stack Overflow and other forums
What will be the Spring Boot Interview Questions for 2 Years Experience?
For candidates with up to 2 years of experience, interviews will typically focus on the core concepts of
Spring Boot, such as auto-configuration, starters, actuator, and CLI. Questions may also be asked
about how to create, configure, run, and deploy Spring Boot applications.
What will be the Spring Boot Interview Questions for 3 Years Experience?
In the interview, candidates with over 3 years of experience are primarily questioned about these
concepts.