55+ Spring Boot Interview Questions To Hire Or Get Hired With

5097 words Read time 24:49

The rise of Spring Boot is thanks to many of the agile software development methodologies and the historic use of Java. Spring Boot is not a framework but an easy way to build a standalone prototype, in often use cases. It's still widely used amongst larger orginzations in an effort to develop a fast product and benchmark its success. Below are some Spring Boot interview questions and answers to help you during the interivew process for when you are undergoing the technology examinations. Often, these will happen in person, behind a whiteboard. Be prepared by answering these questions in your own way, in advance. I would recommend sitting down with a friend and asking for their assistance in reviewing your delivery of the answers.

1. What is Spring Boot?

First of all, it is important to understand that Spring Boot is NOT a framework but rather, an easy way of creating stand-alone applications with little or no configurations. This approach is used to develop spring-based applications that have fewer configurations. One of the best features about Spring Boot is that it leverages the existing spring projects and third party projects to develop production-ready applications.

2. Name the major advantages of using Spring Boot

• The development of Spring-based applications is easy with the help of Java or Groovy.
• Spring Boot requires less development time and increases productivity.
• Spring Boot does not require lots of boilerplate Code, XML configuration and Annotations to be written.
• Spring Boot Applications can easily be integrated with Spring Ecosystems such as Spring JDBC, Spring ORM, Spring Data, and Spring Security etc.
• Spring Boot follows “Opinionated Defaults Configuration” in order to reduce development effort.
• Spring Boot applications provide embedded HTTP servers such as Tomcat and Jetty to develop and test web applications easily.
• Spring Boot provides Command Line Interface (CLI) tool s in order to develop and test Spring Boot applications such as Java or Groovy.
• Spring Boot provides a variety of plugins to develop and test Spring Boot Applications using in-built tools such as Maven and Gradle.

3. What are some of the disadvantages of using Spring Boot?

• While using Spring Boot, converting an existing or legacy Spring Framework into a Spring Boot Application is tough and time-consuming.
• Why is Spring Boot opinionated?
• This is because Spring Boot follows the “Opinionated Defaults Configuration” Approach in order to reduce the development effort.
• How does Spring Boot work and how does it now what to configure?
• In Spring Boot, auto-configuration takes place by analyzing the classpath. If you happen to forget a dependency, Spring Boot can’t configure it. Spring Boot works with tools such as Maven, Gradle and Ant/Ivy.

4. How are properties defined in Spring Boot?

Properties in Spring Boot are defined in the file that exists in a classpath of application as follows. Example: configure default DataSource bean. database.user=admin

5. Why should you use Spring Boot?

• Operate independently
• Simplified configuration
• Automatic configuration
• No code generation and XML configuration
• Application monitoring
• Easy to get started

6. What are the core configuration files in Spring Boot?

The core configuration files in Spring Boot are the application and bootstrap configuration files. The application configuration files are easy to understand as they are primarily used for automated configuration of Spring Boot projects.

The bootstrap configuration files on the other hand have the following scenarios.

• Some fixed attributes that cannot be overridden
• Some encryption/decryption scenarios

7. What is JavaConfig in Spring Boot?

Spring JavaConfig is a product of Spring Boot that provides pure Java methods for the configuration of Spring IOC containers. Ideally, JavaConfig helps to avoid using XML configuration.

8. What are the advantages of using JavaConfig?

• Object-oriented configuration: Since JavaConfig defines its configuration as a class; users can take advantage of Java’s object-oriented configuration. • Elimination of XML configuration: despite the fact that externalized configuration improves the efficiency of web applications based on the principle of dependency injection, most developers try to avoid switching back and forth between XML and Java. JavaConfig offers a pure Java way of configuring spring containers similar to how the XML configuration works. Whereas most developers often assume that it is ideal to always JavaConfiq with XML, it is possible to configure the container using only JavaConfig.
• Refactoring friendly: JavaConfig has a type-safe way of configuring the Spring container that to Java 5.0 support for generics.

9. What are the two main ways of enabling Spring Boot features?

• Inherit the spring-boot-starter-parent project
• Import spring-boot-dependencies project dependencies

10. What are the main features of Spring Boot?

• Web Development
• Spring Application
• Application occasions and listeners
• Admin highlights
• Externalized Configuration
• Properties Files
• YAML Support
• Type-safe Configuration
• Logging
• Security

11. How do developers make Spring Boot venture utilizing Spring initializr?

The spring initializr is a web-based application that produces the Spring Boot project structure. However, the Spring Initializer does not necessarily create an application code. Despite this, the initializer gives the user an essential project structure using either a Maven or a Gradle-built specification. Below are some of the ways that a Spring Initializr can be utilized.

• An online interface.
• Via Spring Tool Suite.
• Using the Spring Boot CLI.

12. Why should you have a Spring Boot Maven module?

The Spring Boot Maven module provides the charges that enable you to package the code as a container as well as run the application. There are several types of Spring Boot Maven modules as outlined below.

• spring-boot-This module operates the Spring Boot module.
• spring-boot: repackage-This module repackages the jug/war to be executable.
• spring-boot: start and spring-boot: stop-These two modules deal with the life-cycle of your Spring Boot application.
• Spring-boot:build-data-this module is utilized by the Actuator.

13. How can you override the default properties in a Spring Boot project?

There are a lot of properties that can be overridden in a Spring Boot application and this overriding is achieved when the default properties are specified in Example: When a developer wants to specify a prefix or suffix in a Spring MVC application, this can be done by entering the properties below in spring.mvc.view.prefix: /WEB-INF/ spring.mvc.view.suffix: .jsp

14. What is referred to as Actuator in Spring Boot?

An actuator is one of the most vital features of Spring Boot. The Actuator is used to access the current state of a running application in a production environment. There are various metrics that are used to establish the current state of an application.

Example: /metrics: This end point shows the developer/user metrics such as free memory, uptime, processors among other properties. Spring Boot actuator helps you monitor your applications in the production environment. Restful points are extremely sensitive which means that they have restricted access and can only be accessed by authenticated users. However, this restriction can be changed by overriding it in

15. What are the main components of Spring Boot?

• Spring Boot Starter
• Spring Boot AutoConfigurator
• Spring Boot Actuator
• Spring Boot CLI
• Spring Boot Initilizer.

16. Name the different forms of Spring Boot initializer.

• Spring Boot initializer comes in the following forms;
• Spring Boot Initilizer With Web Interface
• Spring Boot Initilizer With IDEs/IDE Plugins
• Spring Boot Initilizer With Spring Boot CLI
• Spring Boot Initilizer With ThirdParty Tools

17. In Spring Boot, name the different types of classification of dependencies.

• Spring – core, beans, context, aop
• Web MVC – (Spring MVC)
• Jackson – for JSON Binding
• Validation – Hibernate Validator, Validation API
• Embedded Servlet Container – Tomcat
• Logging – logback, slf4j

18. What are some of the Starter Project Options that are provided by Spring Boot?

Spring Boot provides starter projects such as typical dependencies that are meant to develop specific type of applications.

• spring-boot-starter-web-services – SOAP Web Services
• spring-boot-starter-web – Web & RESTful applications
• spring-boot-starter-test – Unit testing and Integration Testing
• spring-boot-starter-jdbc – Traditional JDBC
• spring-boot-starter-hateoas – Add HATEOAS features to your services
• spring-boot-starter-security – Authentication and Authorization using Spring Security
• spring-boot-starter-data-jpa – Spring Data JPA with Hibernate
• spring-boot-starter-data-rest – Expose Simple REST Services using Spring Data REST

19. What is the difference between JPA and Hibernate?

• JPA is a specification/Interface • Hibernate is one of JPA implementations

20. What are the steps taken to deploy your application (typically) on a virtual machine?

• Step 1: Install Java • Step 2: Install the Web/Application Server (Tomcat/Websphere/Weblogic etc) • Step 3: Deploy the application war

21. Which is the core annotation for Spring Boot?

The @SpringBootApplication is the core annotation above the startup class in Spring Boot. The @SpringBootApplication has the following combinations.

• @SpringBootConfiguration: Combines the @Configuration annotation to implement the configuration file.
• @EnableAutoConfiguration: Turns on and off automatic configuration by turning off the data auto-configuration.
• @ComponentScan: Spring component scan.

22. Does Spring Boot require a separate container to run?

Spring Boot does not require a separate container to run as it has in-built containers such as Tomcat and Jetty.

23. Which are the ways that Spring Boot runs?

• By packing commands or putting them together into a container.
• By running the application with Maven/Gradle plugin.
• By directly executing the main method in run.

24. What is the function of Swagger in Spring Boot?

Swagger is a tool that generates visual representations of RESTful web services, full framework implementations and specifications.

25. What is the Spring Boot initializer used for?

A Spring Boot initializer is a tool used to bootstrap Spring Boot applications easily. The Spring Boot initializr comes in the following forms;

• Spring Boot Initializer With Web Interface.
• Spring Boot Initializer With IDEs/IDE Plugins.
• Spring Boot Initializer With Spring Boot CLI.
• Spring Boot Initializer With ThirdParty Tools.

26. What are the main features of Spring Boot applications?

• In Spring Boot, applications development is faster as Spring Boot can perform many configurations automatically.
• Spring Boot has support for Jetty, Undertow and Tomcat servers with a default port 8080.
• When using Spring Boot, it is possible to externalize configurations so that the user can work with the same application code in different environments. Users can use properties files such as YAML files, environment variables and command-line arguments to externalize configuration.
• When using Spring Boot, Common Loggings are used for all internal logging but the user can also implement our Logging.
• Spring Boot provides auto-configuration for Elasticsearch, Solr, Redis, MongoDB, Neo4j and Cassandra NoSQL technologies.
• In Spring Boot applications, auto-configuration is done for the necessary infrastructure to send and receive messages using JMS.
• Spring boot uses inside java main method to bootstrap the application.
• Spring Boot provides a @SpringBootTest annotation to test spring boot application.

27. How do you create a Spring Boot Project using a Spring Initializer?

When creating a Spring Boot Project, go to the spring initializer URL and follow the following steps:

• Select a Maven or a Gradle project.
• Select the language to be used such as Java, Kotlin or Groovy.
• Select the Spring Boot version to be used.
• Specify the artifacts coordinates’ i.e. group and artifact name.
• Select the dependencies required by the project.
• click on Generate Project button. A project will get started to download.

28. What are the Spring Boot Starters?

There are several types of Spring Boot starters used for different purposes when starting a Spring Boot application. Some of the Spring Boot starters are;

• spring-boot-starter-parent: It is a special starter that provides useful Maven defaults. It is used in parent section in the POM.
• spring-boot-starter-web: Starter for building web and RESTful application with MVC.
• spring-boot-starter-security: Starter for using Spring Security.
• spring-boot-starter-web-services: Starter for using Spring web services.
• spring-boot-starter-thymeleaf: Starter for Spring MVC using Thymeleaf views.
• spring-boot-starter-freemarker: Starter for Spring MVC using FreeMarker views.

29. What is the role of @EnableAutoConfiguration annotation?

@EnableAutoConfiguration annotation enables autoconfiguration required in Spring Boot applications. Autoconfiguration in Spring Boot applications is dependent on classpaths and beans.

30. What are frequently used commands to create and run Spring Boot Applications?

1. For Maven

• mvn dependency:tree: Prints tree of JAR dependencies.
• mvn clean eclipse:eclipse: Creates .classpath
• mvn clean package: Creates JAR/WAR for the application.
• mvn spring-boot:run: Starts tomcat to run application in exploded form.

2. For Gradle

• gradle dependencies: Prints list of direct and transitive dependencies. • gradle clean eclipse: Creates .classpath • gradle clean build: Creates JAR/WAR for the application. • gradle bootRun: Starts embedded tomcat server to run application in exploded form for web application.

31. How do we use a custom banner in Spring Boot applications?

A custom banner is used as follows in Spring Boot applications;

• Text Banner: For text banner just create a file named as banner.txt with desired text and keep it at the location src\main\resources.
• Image Banner: For image banner just create a file named as banner.gif and keep it at the location src\main\resources.
• In the we can configure following banner properties.
• banner.charset: It configures banner encoding. Default is UTF-8.
• banner.location: It is banner file location. Default is classpath:banner.txt
• banner.image.location: It configures banner image file location. Default is classpath:banner.gif. File can also be jpg, png.
• banner.image.width: It configures width of the banner image in char. Default is 76.
• banner.image.height: It configures height of the banner image in char. Default is based on image height.
• banner.image.margin: It is left hand image margin in char. Default is 2.
• banner.image.invert: It configures if images should be inverted for dark terminal themes. Default is false.

32. What are the advantages of using Spring Boot for building out micro-services?

Building out micro-services suing Spring Boot has the following advantages;

• Spring Boot has opinionated views of the Spring Platform and third-party libraries. This means that Spring developers can access tools easily in order to create standalone applications that can be embedded with properties such as Jetty or Tomcat.
• Spring Boot offers production-ready services for building micro-services.
• Spring Boot has an embedded pre-configured Tomcat server.
• Spring Boot provides executable JAR packaging as well as a host of useful decencies.
• Spring Boot requires minimal configuration overheads thus allowing it to be customized to meet the developmental needs of micro-services.
• The Actuator feature of Spring Boot has basic health-checks and monitoring functions that are useful for micro-services.

33. What is Docker and what is its purpose in Spring Boot?

In Spring Boot applications, a Docker is the tool that allows for easier deployment and running of applications. Dockers assist developers design all-inclusive packages of the applications. From a social aspect, Docker can be described as a Linux container management toolkit. Dockers assists users in publishing container images.

34. What is swagger and how do you add it to Spring Boot?

Swagger in Spring Boot is useful for documenting REST API. Swagger is used specify the method, URL, representation as well as other formats used to describe REST web services. Ideally, Swagger offers Spring developers and users tools to generate/compute the documentation of various application codes.

In order to add Swagger to Spring Boot, the following steps are followed.

1) Generation of swagger documentation with spring boot: Docket configuration has to take place as well as linking some dependencies to Swagger before any document generation can take place. For starters, the Swagger UI adds visual representations of the documentation in addition to helping in the execution of test requests.

2) Viewing of the generated swagger documentation: When the application is restarted, Swagger documentation can be viewed by visiting URL http://localhost:8080/v2/api-docs. The Meta information with regards to the API is found at the top of the specific documentation.

35. What are some of the unique features of Spring Book CLI?

• No Semicolons
• No Public and private access modifiers
• No Imports (Most)
• No “return” statement
• No setters and getters
• No Application class with main () method (It takes care by SpringApplication class)
• No Gradle/Maven builds
• No separate HTTP Servers

36. How do you use LiveReload with Spring Boot development tools?

In a Spring Boot MVC project, web browsers and servers are involved. During the development process, in order to get updated data, the user must restart the server and browser whenever there is a change in the name of a file. However, Spring Boot developers have automatized these two tasks through the use of LiveReload in the browser. Below are the steps to follow when using LiveReload in browser.

• Follow the LiveReload extension link and install it.
• Ensure that spring-boot-devtools is installed.
• The Spring Boot developer tool will start a LiveReload server.
• Users can enable or disable LiveReload in Spring Boot applications.
• When mvn spring-boot:run is run in order to update the code, the application will auto-restart and the page refreshed.

37. What is the difference between RequestMapping and GetMapping?

• RequestMapping is generic - you can use with GET, POST, PUT or any of the other request methods using the method attribute on the annotation.
• GetMapping is specific to GET request method. It’s just an extension of RequestMapping to improve clarity.

38. How does one deploy to a different server using Spring Boot?

When deploying to a different server using Spring Boot, there are two steps that are followed;

• Generate a war from the project.
• Deploy it to your favorite server (Websphere or Weblogic or Tomcat or …).

39. What happens in the background when a Spring Boot Application is run as a Java Application?

When the user is using Eclipse IDE, Eclipse makes sure that any changes to the class file or an addition of a dependency is compiled and ready in the target folder. After this process, any Spring Boot Application will just be like any other Java Application.

40. What is Spring Data?

The objective of Spring Data is to provide a consistent and familiar Spring-based programming model. This is done to provide access to data while still retaining the special traits that the underlying data have. In simple terms, Spring Data makes it easier t access and use data technologies, map-reduce frameworks, relational and non-relational databases and cloud-based services.

41. What are the main functions of Spring-Boot-Maven-Plugin?

The spring-boot-maven-plugin has several commands that allow you to package the code in form of JAR or run the application. Below are some of the commands found in the spring-boot-maven-plugin;

• spring-boot:run runs your Spring Boot application.
• spring-boot:repackage repackages your jar/war to be executable.
• spring-boot:start and spring-boot:stop to manage the lifecycle of your Spring Boot application (i.e. for integration tests).
• spring-boot:build-info generates build information that can be used by the Actuator.

42. Explain the steps of setting up a maven project manually.

In Eclipse, Use File -> New Maven Project to create a new project.

• Add dependencies.
• Add the maven plugins!
• Add the Spring Boot Application class

43. What is the minimum baseline Java Version for Spring Boot 2?

Spring Boot 2.0 requires Java 8 or later. Java 6 and 7 are no longer supported.

44. What are the other Starter Project Options that Spring Boot provides?

Spring Boot provides a number of starter projects in addition to the typical dependencies meant to develop specific-type applications. These starter projects are;

• spring-boot-starter-web-services - SOAP Web Services
• spring-boot-starter-web - Web & RESTful applications
• spring-boot-starter-test - Unit testing and Integration Testing
• spring-boot-starter-jdbc - Traditional JDBC
• spring-boot-starter-hateoas - Add HATEOAS featur
es to your services
• spring-boot-starter-security - Authentication and Authorization using Spring Security
• spring-boot-starter-data-jpa - Spring Data JPA with Hibernate
• spring-boot-starter-data-rest - Expose Simple REST Services using Spring Data REST

45. In what types can Spring Boot dependencies be classified into?

Spring Boot dependencies can be classified into;

• Spring - core, beans, context, aop
• Web MVC - (Spring MVC)
• Jackson - for JSON Binding
• Validation - Hibernate Validator, Validation API
• Embedded Servlet Container - Tomcat
• Logging - logback, slf4j

46. Explain the difference between Spring Boot, Spring MVC and Spring.

One of the most important features of a Spring framework is that it is Dependency Injection. The core of all Spring Modules is IOC (Inversion of Control) or Dependency Injection. When Dependency Injection or IOC is used appropriately, users can develop loosely-coupled applications which can easily be tested.

The Spring MVC Framework provides a couple of ways to develop web applications such as by using concepts such as Dispatcher Servlet, ModelAndView and View Resolver.

The main problem about the Spring Framework and Spring MVC is the amount of configuration that is required. This is where Spring Boot comes in. Spring Boot has auto configuration as well as other non-functional features that make it easier to build production-ready applications.

47. What is the difference between RequestMapping and GetMapping?

RequestMapping is generic: RequestMapping can be used with GET, POST, PUT and many other request methods using the method attribute on the annotation.

GetMapping is specific: GetMapping is an extension of RequestMapping to improve clarity on requests.

48. Why is it not advisable to use Spring DateRest in real-world applications?

While Spring DataRest does an excellent job in prototyping, it is not recommended for big applications. This is because when using Spring DataRest, the database entities operate as REST Services. During the design of RESTful services, the interface being used should have the following key features;

• The domain model
• The consumers

When using Spring Data REST, your entities are exposed as REST Services. This means that while Spring Data REST is good for prototyping, it may not be such a great idea to use when a project is fully evolved.

49. What is the difference between JPA and Hibernate?

In simple terms;

• JPA is a specification/Interface
• Hibernate is one of JPA implementations

When a JPA is used, annotation and interfaces from javax.persistence package without using Hibernate import packages.

50. How can you best expose custom application configuration with Spring Boot?

A configuration component can be defined using @ConfigurationProperties.
public class BasicConfiguration {
private boolean value;
private String message;
private int number;
The values can be configured in
basic.value: true
basic.message: Dynamic Message
basic.number: 100

51. What are the different environments for enterprise application development?

• Dev
• QA
• Stage
• Production

52. How is Spring Boot WAR deployed to Tomcat?

When deploying Spring Boot WAR to Tomcat, the following steps are followed.

• Download Apache Tomcat.
• Unpackage the same into the desired tomcat folder.
• Copy the WAR file from the target/spring-boot-tomcat.war into the tomcat/webapps/ folder.
• From a terminal, go to tomcat/bin folder.
• Execute the file.

53. What are annotations in Spring Boot?

In a Spring Boot framework, annotations promote and implement the principles of IOC (control inversion) and DI (dependency injection). Annotations therefore allow developers to manage bean dependencies using the XmL-based configuration. Annotations and their dependencies can also be defined in a Java-based configuration that instead uses Spring annotations. Different from the XML approach, a Java-based configuration creates programs to manage bean components.

54. Can you control logging with Spring Boot? How do you do it?

It is possible to control logging with Spring Boot by specifying the log-levels on the file. Spring Boot always loads this file if it is present in the classpath and can be used in the configuration of both Spring Boot and the application code.

Since Spring Boot uses Commons Logging for internal logging, it is possible to change the log levels by adding the line below in the file.


55. What are the main security properties in Spring Boot?

• security.basic.enabled: It enables basic authentication. Default value is true.
• security.basic.path: It configures paths to apply security. We need to provide comma separated paths.
• security.enable-csrf: It enables CSRF. Default value is false.
• security.require-ssl: It enables and disables SSL. Default value is false.
• security.sessions: Default value is stateless. Values can be always, never, if required, stateless.
• It configures user name. Default user is user.
• security.user.password: It configures password.
• security.user.role: It configures role. Default role is USER.

56. What are Spring Boot Starter Projects?

Starters in Spring Boot are a set of convenient descriptors that are included in Spring Boot applications. Starters come with a variety of Spring-related technology making the process of application development with Spring Boot much easier. With Starter Projects, you don’t have to search for a sample code or try to copy and paste a load of descriptors.


If you are using Spring or JPA for database access, you can include the spring-boot-starter-data-jpa dependency in your project and that’s it. Another example is when you are using Spring Boot Starter Web. When trying to deveoop a Spring Boot web application that exposes its RESTful services, then Spring Boot Start Web is the starter of choice. A quick project using Spring Initializr and Spring Boot Starter Web would look like this;

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

57. What are Embedded Servers and why are the important in Spring Boot applications?

here are so many benefits that arise from deploying your application on a virtual machine. When doing this, consider the following steps;

• Step 1 : Install Java
• Step 2 : Install the Web/Application Server (Tomcat/Websphere/Weblogic etc)
• Step 3 : Deploy the application war

Considering a scenario where you want to make the server part of the application, all you need is a virtual machine installed with Java and you can directly deploy an application on a virtual machine. This is the whole idea behind Embedded Servers.

In a Spring Boot application, it is possible to generate an application JAR that contains an Embedded Tomcat. This means that you can still run your application like a normal Java application. In simple terms, embedding a server refers to when a deployable unit has binaries for the server i.e. (tomcat.jar).

Share this article


Reach out