preloader
Spring Boot Interview Questions

Top 50 Spring Boot Interview Questions for 2022 Job Interviews

author image

Candidates who are appearing for a technical interview can prepare their Spring Boot Interview Questions from this page. Here we have given 50 Spring Boot Interview Questions and Answers which can be asked in the job interview. Read on to know more about Spring Boot topics and coding from the below section.

About Spring Boot: It is an open-source Java framework used to make a micro Service. It is created by Pivotal Team for making build stand-alone spring-based applications.

Spring Boot Interview Questions

1. Explain Spring Boot?

2. Tell me some benefits of Spring Boot?

3. Tell the features of Spring Boot?

4. By using Maven, How you'll create a Spring Boot application?

5. Explain @RestController annotation in Spring Boot?

6. Explain Spring Boot dependency management?

7. Tell about Spring Boot properties?

8. Explain Spring Boot Starters?

9. What is Spring Boot Actuator?

10. Explain thymeleaf?

11. How to use thymeleaf?

12. Tell me the way to connect Spring Boot to the database by using JPA?

13. Tell me the way to connect the Spring Boot application to the database by using JDBC?

14. Explain @RequestMapping annotation in Spring Boot?

15. Spring Vs Spring Boot?

16. When a Spring Boot Application is “Run as Java Application” then what happens in the background?

17. Tell the requirements for a spring boot System.

18. Name some Spring Boot key components?

19. Why Spring Boot over Spring?

20. Name some starter dependency of the Spring boot module?

21. What is the working of Spring Boot?

22. What @SpringBootApplication annotation does internally?

23. Tell me the objective of using @ComponentScan in the class files?

24. How does a spring boot application get started?

25. Explain Spring Initializer?

26. Explain Spring Boot CLI and its benefits?

27. Tell about the Annotations that Spring Boot Offers?

28. Do we make a non-web application in Spring Boot?

29. Can we change the port of the implanted Tomcat server in Spring Boot?

30. Name the default port of tomcat in spring boot?

31. Are we able to override or substitute the Embedded tomcat server in Spring Boot?

32. Are we able to disable the default web server in the spring boot application?

33. Tell me how will you disable a specific auto-configuration class?

34. Differentiate between @Controller and @RestController in Spring Boot?

35. Differentiate between GetMapping and RequestMapping?

36. What are the actuator-provided endpoints used for observing the Spring boot application?

37. Tell me the way to get the list of all the beans in your Spring boot application?

38. How to inspect the environmental properties in Spring Boot application.

39. Tell all the ways to enable debugging log in the spring boot application?

40. Explain IOC container?

41. How to deploy another server with Spring Boot?

42. Tell the steps to link an external database like MySQL or Oracle?

43. How is Hibernate selected as the default execution for JPA without any configuration?

44. How to guide an auto-configuration to reinforce when a bean exists?

45. Tell me the layer where the boundary of a transaction start?

46. How does path=”sample”, collectionResourceRel=”sample” work with Spring Data Rest?

47. Tell the way to register a custom auto-configuration.

48. How are you Configuring Log4j for logging?

49. Can you use jetty rather than tomcat in spring-boot-starter-web?


Learn More Interview Questions Here:


Spring Boot Interview Questions and Answers

1. Explain Spring Boot?

It is a Spring module that gives RAD (Rapid Application Development) characteristics to the Spring framework. It makes a stand-alone spring-based application that you can operate because it requires very little spring configuration

2. Tell me some benefits of Spring Boot?

  • It makes stand-alone Spring applications that can be initiated using java -jar.
  • Embed Tomcat, Undertow, or Jetty directly. You don’t require to deploy WAR files.
  • It gives opinionated ‘starter’ POMs to streamline your Maven configuration.
  • Whenever possible, it automatically configures Spring.

3. Tell the features of Spring Boot?

  • Web Development
  • Application events and listeners
  • Admin features
  • SpringApplication

4. By using Maven, How you'll create a Spring Boot application?

There are numerous methods to create a Spring Boot project. Here are some methods which can be used in creating a Spring Boot application.

  • Spring Maven Project
  • Spring Boot CLI
  • Spring Initializr
  • Spring Starter Project Wizard

5. Explain @RestController annotation in Spring Boot?

The @RestController is a typecast annotation. It adds @ResponseBody and @Controller annotations to the class. We ought to import org.springframework.web.bind.annotation package in our file, to execute it.

6. Explain Spring Boot dependency management?

Spring Boot automatically handles dependencies and configuration. You need not determine the version for any of that dependencies. When Spring Boot is upgraded it automatically upgrades all dependencies.

7. Tell about Spring Boot properties?

Spring Boot gives different properties that can be found inside our project’s application.properties file. These properties have preset default values and you can arrange that inside the properties file. Properties are used to assign values hilike: server-port number, database connection configuration, etc.

8. Explain Spring Boot Starters?

Starters are a group of suitable dependency descriptors that can be included in our application. Spring Boot gives already builds starters that make development effortless and quick. Like, if you want to create using spring and JPA for database access, and then include the spring-boot-starter-data-jpa dependency in your project.

9. What is Spring Boot Actuator?

Spring Boot gives an actuator to monitor and handle our application. An actuator is a tool that contains HTTP endpoints. When an application is forced to production, you can control and monitor your application by using HTTP endpoints.

10. Explain thymeleaf?

Thymeleaf is a server-side Java template machine used for a web application. Its primary goal is to obtain refined natural templates for web applications. It can be incorporated with Spring Framework and is perfect for HTML5 Java web applications.

11. How to use thymeleaf?

To use Thymeleaf we must add it into our pom.xml file like:

org.springframework.boot

spring-boot-starter-thymeleaf

12. Tell me the way to connect Spring Boot to the database by using JPA?

Spring Boot gives spring-boot-starter-data-jpa starter to link Spring application with relational database proficiently. You can use the starter in the project POM (Project Object Model) file.

13. Tell me the way to connect the Spring Boot application to the database by using JDBC?

Spring Boot gives starters and libraries for linking our application with JDBC. You can make an application by creating and setup JDBC with Spring Boot to connect with the Mysql database.

14. Explain @RequestMapping annotation in Spring Boot?

The annotation is used to deliver routing details. It conveys to the spring that any HTTP proposal should be mapped to the related method. We require importing org.springframework.web.annotation package in our file.

15. Spring Vs Spring Boot?

Spring is a web-based application framework established on Java. It gives tools and libraries to make a fully customized web application.

Whereas Spring Boot is a module of spring used to make spring application projects that can just execute.

16. When a Spring Boot Application is “Run as Java Application” then what happens in the background?

When a Spring Boot application is implemented as “Run as Java application”, then it automatically launches up the tomcat server as they come to know that you are designing a web application.

17. Tell the requirements for a spring boot System.

Spring Boot 2.1.7.RELEASE requires

  • Java 8 +
  • Spring Framework 5.1.9 +

Explicit build support

  • Maven 3.3+
  • Gradle 4.4+

Servlet Container Support

  • Tomcat 9.0 – Servlet Version 4.0
  • Jetty 9.4 – Servlet Version 3.1
  • Undertow 2.0 – Servlet Version 4.0

18. Name some Spring Boot key components?

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

19. Why Spring Boot over Spring?

Here are some key points that spring boot offers but spring doesn’t:

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

20. Name some starter dependency of the Spring boot module?

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

21. What is the working of Spring Boot?

By using annotation, it automatically configures your application on the basis of dependencies that you have added to the project. The entrance point of the spring boot application is the class that holds @SpringBootApplication annotation and the primary method.

Spring Boot automatically checks all the components contained in the project by using @ComponentScan annotation.

22. What @SpringBootApplication annotation does internally?

The @SpringBootApplication annotation is equal to using @Configuration, @ComponentScan, and @EnableAutoConfiguration with their default attributes. Spring Boot allows the programmer to use a single annotation rather than using multiple. But, Spring delivered loosely coupled characteristics that can be used for each annotation as per the project requirements.

23. Tell me the objective of using @ComponentScan in the class files?

Spring Boot application examines all the beans and package declarations when the application prepares. You do require to add the @ComponentScan annotation in the class file to scan the elements added to the project.

24. How does a spring boot application get started?

Similar to any Java program, a Spring Boot application should have a primary method. This method acts as an entryway that summons the SpringApplication#run method to bootstrap the application. @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class); // other statements } }

25. Explain Spring Initializer?

It is a web application that allows you to make an initial spring boot project layout and gives a maven or gradle file to create your code. It decodes the issue of setting up a framework when you are creating a project from scrap.

26. Explain Spring Boot CLI and its benefits?

Spring Boot CLI stands for Spring Boot command-line interface that permits you to make a spring-based java application using Groovy.

Example: You need not make getter and setter process or access modifier, return statement. If you are using the JDBC template, it automatically does it for you.

27. Tell about the Annotations that Spring Boot Offers?

The main annotation lies in org.springframework.boot.autoconfigure and its sub-packages. Here are some of them:

@EnableAutoConfiguration: It is to create Spring Boot search for auto-configuration beans on its classpath and automatically spread them.

@SpringBootApplication: It is used to represent the primary class of a Boot Application. This annotation incorporates @Configuration, @ComponentScan, and @EnableAutoConfiguration annotations with their default attributes.

28. Do we make a non-web application in Spring Boot?

Yes, we can make a non-web application by eliminating the web dependencies from the classpath along with altering the way Spring Boot makes the application context.

29. Can we change the port of the implanted Tomcat server in Spring Boot?

Yes, by using the server.port in the application.properties we can change the port of the embedded Tomcat server in Spring Boot.

30. Name the default port of tomcat in spring boot?

The default port of the tomcat server-id 8080. It can be modified by adding sever.port properties in the application.property file.

31. Are we able to override or substitute the Embedded tomcat server in Spring Boot?

Yes, by using the Starter dependency in the pom.xml file we can substitute the embedded Tomcat server with any server. For example, spring-boot-starter-jetty can be used as a dependency for using a jetty server in your project.

32. Are we able to disable the default web server in the spring boot application?

Yes, by using application.properties to configure the web application type i.e spring.main.web-application-type=none we are able to disable the default web server in the spring boot application.

33. Tell me how will you disable a specific auto-configuration class?

By using exclude attribute of @EnableAutoConfiguration if you require auto-configuration then, not apply to any specific class.

//use of exclude

@EnableAutoConfiguration(exclude={className})

34. Differentiate between @Controller and @RestController in Spring Boot?

@Controller Map of the model object to view or template and make it in a way that human can read it whereas @RestController just returns the object and object data is instantly written in HTTP response as JSON or XML.

35. Differentiate between GetMapping and RequestMapping?

The @GetMapping is a written annotation that works as a shortcut for @RequestMapping (method = RequestMethod.GET). Both these processes support consumes. The consume options are:

consumes = “text/plain”
consumes = {“text/plain”, “application/*”}

36. What are the actuator-provided endpoints used for observing the Spring boot application?

  • Health
  • Beans
  • Info
  • Shutdown
  • Mappings
  • Httptrace
  • Configprops
  • Threaddump
  • Heapdump

37. Tell me the way to get the list of all the beans in your Spring boot application?

By using Spring Boot actuator “/Beans” you can get the complete list of all the beans.

38. How to inspect the environmental properties in Spring Boot application.

Spring Boot actuator “/env” returns the complete list of all the environment properties.

39. Tell all the ways to enable debugging log in the spring boot application?

There are three ways through which Debugging logs can be enabled:

  • Start the application with –debug switch.
  • Set the logging.level.root=debug property in application.property file.
  • Set the logging level of the root logger to debug in the provided logging configuration file.

40. Explain IOC container?

It is a framework for enforcing automatic dependency injection. It handles object creation and its lifetime and also injects dependencies into the class.

41. How to deploy another server with Spring Boot?

  • Develop a WAR from the project
  • Then, deploy the WAR file to your favorite server

Note: The above steps depend on the server you choose.

To link an external database, follow the below steps:

  • Begin by adding the dependency for MySQL Connector to pom.xml
  • Then delete H2 Dependency from pom.xml
  • Now, arrange your MySQL database and configure your link to the MySQL database
  • Restart your project

43. How is Hibernate selected as the default execution for JPA without any configuration?

When Spring Boot Auto Configuration has been used, it automatically adds the spring-boot-starter-data-jpa dependency to the pom.xml file. Now, since this dependency has a transitive dependency on JPA and Hibernate, Spring Boot spontaneously auto-configures Hibernate as the default execution for JPA, whenever it notices Hibernate in the classpath.

44. How to guide an auto-configuration to reinforce when a bean exists?

By using @ConditionalOnMissingBean annotation we can guide an auto-configuration class to reinforce when a bean exists. The attributes are as follows:

  • value: This attribute reserves the type of beans to be checked
  • name: This attribute reserves the name of beans to be checked

45. Tell me the layer where the boundary of a transaction start?

From the Service Layer the boundary of the transaction start since the logic for the business transaction is available in this layer itself.

46. How does path=”sample”, collectionResourceRel=”sample” work with Spring Data Rest?

@RepositoryRestResource(collectionResourceRel = “sample”, path = “sample”)
public interface SampleRepository extends
PagingAndSortingRepository<Sample, Long>

Path: This section is used to cite the segment under which the resource is to be shipped.

collectionResourceRel: This value is utilized to make links to the collection resource.

47. Tell the way to register a custom auto-configuration.

Mention the fully-qualified name beneath the @EnableAutoConfiguration key META-INF/spring. factories file to register an auto-configuration class. Also, In case it is built with maven, then this file should be located in the resources/META-INT directory.

48. How are you Configuring Log4j for logging?

As Spring Boot supports Log4j2 for logging a configuration, you have to remove Logback and retain Log4j2 for logging. It is done only if you are using the starter project.

49. Can you use jetty rather than tomcat in spring-boot-starter-web?

Yes, jetty can be used rather than tomcat in spring-boot-starter-web, by eliminating the current dependency and adding the following: &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt; &lt;exclusions&gt; &lt;exclusion&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt; &lt;/exclusion&gt; &lt;/exclusions&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; &lt;artifactId&gt;spring-boot-starter-jetty&lt;/artifactId&gt; &lt;/dependency&gt;

Want to prepare for these languages:

Recent Articles