SpringBoot Interview Questions

In this article we will explore interview question that you might expect in your interview from basic to advance level.

1. What is Spring boot and and it’s main features ?

Spring Boot is a Java-based framework designed to simplify the process of building and deploying web applications and microservices. It is built on top of the Spring Framework, and it provides a set of conventions, tools, and features to speed up development.

Key Features
  1. Auto-Configuration:
    • Automatically configures your application based on the dependencies present in the classpath.
    • Reduces the need for extensive XML or Java-based configuration.
  2. Embedded Servers:
    • Comes with embedded web servers like Tomcat, Jetty, or Undertow, allowing you to run applications without external dependencies.
    • Simplifies the deployment process.
  3. Spring Boot Starter Dependencies:
    • Provides a set of curated dependencies (e.g., spring-boot-starter-web, spring-boot-starter-data-jpa) for various use cases.
    • Minimizes the effort to manage dependencies manually.
  4. Production-Ready Features:
    • Includes monitoring, health checks, and metrics with Spring Boot Actuator.
    • Supports logging, tracing, and application insights out of the box.
  5. Opinionated Defaults:
    • Comes with sensible defaults, which can be overridden if needed.
    • Ensures faster development while maintaining flexibility.
  6. Externalized Configuration:
    • Supports configuration through properties or YAML files (e.g., application.properties or application.yml).
    • Facilitates different configurations for environments (e.g., dev, staging, production).

2. What are some common use case for SpringBoot ?

  • Building RESTful APIs
  • Developing microservices
  • Rapid prototyping
  • Full-stack web applications

3. Do you know difference between Spring and SpringBoot ?

Spring requires extensive configuration (XML/Java), while Spring Boot minimizes this with auto-configuration. Spring Boot includes embedded servers (e.g., Tomcat, Jetty) for running applications without deploying WAR files. Spring Boot provides curated starter dependencies.

4. What are different ways to create SpringBoot application ?

  1. Using Spring Initializer
  2. Using CLI
  3. Directly putting SpringBoot Maven Dependency in POM

5. List down some popular SpringBoot starters

  1. spring-boot-starter : core starter, including auto-configuration support, logging and YAML
  2. spring-boot-starter-web : for building web, including RESTful, applications using Spring MVC
  3. spring-boot-starter-test : for testing Spring Boot applications
  4. spring-boot-starter-security : for using Spring Security

6. What does the @SpringBootApplication annotation do internally?

Many Spring Boot developers like their apps to use auto-configuration, component scan and be able to define extra configuration on their “application class”. A single @SpringBootApplication annotation can be used to enable those three features, that is:

7. What are the Spring Boot key components?

Spring Boot Framework has mainly four major Components.

  • Spring Boot Starters
  • Spring Boot AutoConfigurator
  • Spring Boot CLI
  • Spring Boot Actuator

8. How does Spring Boot works?

Below is how the Application class looks like

 @SpringBootApplication
   public class MySpringBootApplication
   {
       public static void main(String[] args) {
           SpringApplication.run(MySpringBootApplication.class, args);
       }
   }

From the run method, the main application context is kicked off which in turn searches for the classes annotated with @Configuration, initializes all the declared beans in those configuration classes, and based upon the scope of those beans, stores those beans in JVM, specifically in a space inside JVM which is known as IOC container. After the creation of all the beans, automatically configures the dispatcher servlet and registers the default handler mappings, messageConverts, and all other basic things.

9. What is the purpose of using @ComponentScan in the class files?

This annotation is used to enable component scanning. In this example, it scans the package “com.example” and its sub-packages for components.

@SpringBootApplication
@ComponentScan(basePackages = "com.example")
public class MySpringBootApplication {
  public static void main(String[] args) {
      SpringApplication.run(MySpringBootApplication.class, args);
  }
}

10. What is Spring Boot CLI and what are its benefits?

The Spring Boot CLI is a command line tool that you can use if you want to quickly develop a Spring application. It lets you run Groovy scripts, which means that you have a familiar Java-like syntax without so much boilerplate code. You can also bootstrap a new project or write your own command for it.

11. What is Spring Initializer?

Spring Initializer generates a ready-to-use project structure for Spring Boot applications. It provides the essential files and dependencies configured according to the selected options, making it easier for developers to kick-start their projects. Just go to spring initialize site, fill in the required details , add dependency and generate project.