Spring Boot Interview Questions

Spring Boot Interview Questions

 

This post is the part of our Interview Questions series and. In this post, we will discuss some of the commonly asked Spring Boot Interview Questions during a job interview.

Refer to Spring Boot Tutorial for more detail about Spring Boot.

 

Q1. What is Spring Boot?

Spring Boot is an opinionated framework for building and running Spring applications. Spring Boot is not a framework for writing applications, think of Spring Boot as a tool which can do these initial tasks for us automatically.

While working on big enterprise projects involving several frameworks, it is very complex to handle all configurations and making sure required dependencies are in place. Spring Boot focuses on developer productivity by providing smart auto configuration modules and handling all configurations and dependencies for us.

Read What is Spring Boot for more detail.

 

Q2. What are the advantages of Spring Boot?

  1. It simplifies Spring dependencies by taking the opinionated view.
  2. Spring Boot provides a preconfigured set of technologies/framework to reduces error-prone configuration so we as a developer focused on building our business logic and not thinking of project setup.
  3. It reduces development code by avoiding a lot of boilerplate code.
  4. Easier to integrate Spring Boot Application with Spring Ecosystem like Spring JDBC, Spring ORM, Spring Data, Spring Security etc.
  5. You really don’t need those big XML configurations for your project.
  6. Embed Tomcat, Jetty or Undertow directly.
  7. Provide opinionated Maven POM to simplify your configuration.

 

Q3. What are the different Spring Boot Components?

  1. Boot Initializer
  2. Spring Boot Starter
  3. Auto Configurator.
  4. Spring Boot CLI.
  5. Actuator.

 

Q4. What is Spring Boot Starters?

Spring Boot Starters are the set of convenient dependency descriptors which can be easily included in any level of application. These starters work as a  bootstrapping process for the Spring related technologies, we no longer need to worry about the dependencies and they will be automatically managed by Spring Boot Starters.

The starters contain a lot of the dependencies that you need to get a project up and running quickly and with a consistent, supported a set of managed transitive dependencies. To summarize, Spring Boot Starters are just JAR files used by Spring Boot for auto-dependency.

 Read Spring Boot Starters for more detail.

 

Q5. Name some of the starter provided by Spring Boot?

  • spring-boot-starter-web: Web and RESTful applications
  • spring-boot-starter-security : Spring Security
  • spring-boot-starter-data-jpa – Spring Data JPA
  • spring-boot-starter-test – Unit testing
  • spring-boot-starter-hateoas – Add HATEOAS features

For a complete list, read Spring Boot Starters List

 

Q6. Can we use Spring Boot for non-Spring application?

No, Spring Boot has limited to Spring based application only. We can not use Spring Boot for non Spring applications.

 

Q7. What are the different options for creating Spring Boot application

There are multiple options to create Spring Boot application. We can use any of the following approaches

  •  Spring Initializer
  • Boot CLI.
  • Using Maven
  • IDE project wizard

Read Building an Application with Spring Boot for detail.

 

Q8. What is Spring Boot Initilizr?

Spring Boot Initilizr is a Spring Boot tool to bootstrap Spring Boot or Spring Applications very easily. Spring Initializr is also integrated with all major Java IDEs along with CLI.

 

Q9. How can I reload my Spring Boot changes without restarting the server?

This is achievable by Spring Boot Dev Tools module.it’s a powerful tool for the development. It helps developers to shorten the development cycle and enable easy deployment and testing during the development.

To enable this feature, add the following dependency to Maven POM file.

<dependencies>
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
  </dependency>
</dependencies>

Read Spring Boot Dev Tools for different features of Dev Tools.

 

Q10. How can we override default properties in Spring Boot?

Spring Boot advocate convention over configuration. Spring Boot externalize application configurations through application.properties file. These properties work as default values for Spring Boot application.

To override these default values, Spring Boot provides following options.

  • Create an application.properties file in the classpath for overriding specific properties for Spring Boot.
    • For Maven based project, this file will be under /src/main/resource.
  • application.yml file in the classpath for overriding specific properties for Spring Boot.
    • For Maven based project, this file will be under /src/main/resource.
  • Through command line switches

e.g. Server HTTP port default to 8080 in the default application.properties file. To change this port to 9090, add below entry in the custom application.properties file

server.port=9090

 

Q11. What are the embedded containers supported by Spring Boot?

Spring Boot includes support for the following embedded containers

  1. Tomcat
  2. Jetty
  3. Undertow.

Use the right “Starter” to configure the embedded container. 

 

Q12. What is Spring Boot Actuator?

The actuator provides production-ready features for Spring Boot application. It will help us to check and manage our application in the production environment. We don’t need any code to get these features since they are available once the actuator dependency is in the class-path. The actuator provides features like auditing, health, metrics, environment information, thread dump etc. using HTTP endpoints. Read Spring Boot Actuator for more detail.

 

Q13. How can we create a custom endpoint in Spring Boot Actuator?

To create a custom endpoint using Spring Boot 1.x, we should expose the instance of the custom endpoint class as a bean. We need to implement Endpoint<T> interface.

@Component
public class CustomEndpoint implements Endpoint {
  //method implimentation
}

Spring Boot 2.x changed it completely by introducing @Endpoint annotation. Spring Boot expose endpoints with @Endpoint@WebEndpointor @WebEndpointExtension over HTTP using Jersey, Spring MVC, or Spring WebFlux.Read Custom Endpoint in Spring Boot Actuator for more detail.

 

In this article, we discussed some the commonly asked Spring Boot Interview Questions during a job interview. If you are preparing for your next interview, read our post on Spring Interview Questions.

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of