Spring Boot Interview Questions

  • 1
    What is the Spring Boot?

    Spring Boot is used to developing stand-alone Java-based applications, which you can just execute. It is a module of Spring, which makes life easier for Java developers. 

  • 2
    What are the major advantages of Spring Boot?

    Some of the major advantages of Spring Boot include the following:

    • It is easier to create stand-alone and production-ready applications.
    • You can use Spring Boot with minimum configurations. You don’t need to have the entire Spring configuration set up.
    • It reduces application development time and increases productivity.
    • It eliminates the need for WAR files. Because it contains Tomcat and Servlet containers jetty.
    • It enables the development and testing of applications by providing the CLI tool.
    • It enables the monitoring and management of applications in development and production environments through its multiple APIs.
  • 3
    When a Spring Boot application is executed as “Run as Java application”, what will happen in the background?

    The tomcat server will be launched in the background.

  • 4
    How do Spring Boot functions?

    Based on the dependencies added to the project, Spring Boot automatically configures the application by using the @EnableAutoConfiguration annotation. Next, it scans all the components included in the project using the @ComponentScan annotation.

  • 5
    What purpose does Spring Boot Starter Actuator dependency serve?

     The Spring Boot Starter Actuator dependency serves the purpose of monitoring and managing the application. Here is the code for it:

  • 6
     Can you explain what happens in the background when a Spring Boot Application is “Run as Java Application”?

    When a Spring Boot application is executed as “Run as Java application”, then it automatically launches up the tomcat server as soon as it sees, that you are developing a web application.

  • 7
    What for Spring Boot Starter Security dependency is used?

    The Spring Boot Starter Security dependency is used for the security of spring.

    Here is its code:

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

  • 8
    Which dependency is used in the creation of web applications?

     The Spring Boot Starter Thyme Leaf dependency is used in the creation of web applications.

  • 9
    How do you create a Spring Boot application using Maven?

    There are different approaches to create a Spring Boot application using maven. Here are they:

    • Spring Boot CLI
    • Spring Starter Project Wizard
    • Spring Initializr
    • Spring Maven Project
  • 10
    What is Spring Boot CLI?

    We can create a Spring Boot project using Spring Initializr by performing the below steps:

    1. Select the Maven project and the required dependencies.
    2. Enter Group, Artifact, and then click on Generate Project.

    The project is downloaded.

      3. Extract the project into your system.

      4. Use the Import option on the Spring Tool Suite IDE to import the project.

  • 11
    What is the spring actuator?

    Spring actuator in Spring Boot allows us to see what happens inside a running application.

  • 12
    Why Spring boot was developed?

    Spring boot was developed as an extension of Spring to overcome the limitations the Spring framework has. Spring boot uses annotation, boilerplate configuration, and reduced code length to help developers quickly deploy and create standalone Spring applications without any configuration overhead.

    In addition, Spring boot also has starters that implicitly handle dependencies, embedded servers such as Tomcat and Jetty, in-memory database support, and a CLI tool for testing and developing applications.

  • 13
    Explain Spring boot starters.

    Added under pom.xml ‘s <dependencies> section, Spring boot Starters are dependency descriptors that organize dependencies of 50+ Starters under a single name.

    The benefits of Spring Boot Starters are as listed below:

    • Reduced configuration time, thereby increasing productivity for developers.
    • Less number of added dependencies makes ease managing the Page Object Model (POM).
    • Dependency configurations are well supported, tested, and ready for production.
    • No need to remember the version and name of the dependencies.
  • 14
    Describe @RestMapping annotation in Spring Boot.

     @RestMapping annotation is used for the controller from both – class level and/or method level. The annotation maps a specific pattern or request path onto a controller. In addition, more mappings specific to handler methods are applied by method-level annotation.

  • 15
    Why is spring-boot-starter-JDBC used?

    This yet another one of the starters in spring boot utilized for the HikariCP connection pool with JDBC. 

  • 16
    Why is spring-boot-starter-web used?

    This starter helps in developing a web application using Spring MVC. It can also be used to build a RESTful application using spring MVC. 

  • 17
    Why we use spring-boot-starter-data-JPA?

    This starter in spring boot allows us to utilize Spring Data JPA with Hibernate.

  • 18
    What is Spring CLI?

    Spring boot CLI can be used to build spring boot applications and avoid boilerplate code.

  • 19
    What is a starter dependency feature in spring boot?

    All the common dependencies are assembled together to improve productivity. This could be achieved by the starter dependency feature in the spring boot. 

  • 20
    What is spring’sSpring’s initializer?

    Spring initializer is a web application capable of generating internal project structure. When you use this feature, you don’t need to set up the internal project structure by yourself. 

  • 21
    Is creating a non-web application in Spring Boot possible? 

    Yes, it is possible to create non-web applications in Spring Boot. For doing so, we would need to remove web dependencies from the classpath and change the way Spring boot creates an application context. 

  • 22
    Why is the YAML file better than the properties file?

    In the YAML file, the data is presented in an ordered fashion or hierarchal manner, which makes debugging easier when developers encounter errors. 

  • 23
    Explain Spring Data REST?

    To expose RESTful resources around Spring Data repositories, Spring data REST will be utilized. The post method could be used to expose the REST service. 

  • 24
    The boundary of a transaction should start with which layer, according to you?

    The boundary of a transaction should start with Service Layer as Spring Layer includes the logic for business transactions. 

  • 25
    How will you add a custom JS code with Spring Boot?

    This could be achieved by following the below-given steps:

    Create a new folder with the name static under the resources folder. Include the static content in this folder. 

  • 26
    What are the attributes of @ConditionalOnMissingBean annotation? 

    The attributes of @ConditionalOnMissingBean annotation are value and name.

  • 27
    How will you notify an auto-configuration to back off when a bean exists?

    By using @ConditionalOnMissingBean annotation, we can notify auto-configuration to back off when a beam exists. 

  • 28
    What dependencies are needed in order to start up a JPA Application and connect to in-memory database H2 with Spring Boot?

    The dependencies require are as follows:

    • web starter
    • h2
    • data JPA starter
  • 29
    How would you control logging with Spring Boot?

    It is possible to control logging with Spring Boot. To accomplish that, we would need to specify the log levels of the application.properties file. 

  • 30
    List some common Spring Boot annotations. 

    Some of the common Spring Boot annotations are-

    • @SpringBootApplication
    • @SpringBootConfiguration
    • @EnableAutoConfiguration
    • @SpringBootTest.
  • 31
    List the embedded containers that Spring boot support?

    All of the embedded containers that Spring Boot support are-

    • Tomcat
    • Jetty
    • Undertow

    Thus Spring boot supports am aggregate of 3 embedded containers. 

  • 32
    What error will you see if H2 is not in the classpath?

    The following error will be shown in the case, h2 is not in the classpath:

    Cannot determine embedded database driver class for database type NONE

  • 33
    Where are the properties in Spring Boot applications defined?

    The properties in Spring boot applications are defined in an application.properties file. Spring initializer can create this file or alternatively, you can create it manually. 

  • 34
    Explain Spring boot CLI and its advantages?

    It is a command-line interface allowing developers to create Spring applications with groovy. 

  • 35
    What is relax binding support in Spring Boot?

    When the property name is not required to match the key of the environment property, it is called relax binding. Spring boot supports relax binding. 

  • 36
     How can you deploy to a distinct server with Spring boot? 

    For doing so, you can generate a WAR file from your project and then deploy it onto your chosen server. 

  • 37
    How to the disable auto-configuration in Spring boot? 

    The auto-configuration feature can be disabled by excluding the attribute of @EnableAutoConfiguration. Spring.autoconfigure.exclude property can also be used to exclude the list of auto-configuration classes.

  • 38
    What is the Spring data?

    Spring data enables developers to access data. It enables us using relational and non-relational databases, cloud-based data services, etc. 

  • 39
    What is JPA?

    A Data Access Abstraction that could decrease the amount of boiler code. 

  • 40
    What is Hibernate?

    The advantage of loose coupling cam is used by Hibernate which is an implementation of the Java Persistence API. 

  • 41
    What is the way to enable HTTP/2 support in Spring Boot?

    In order to enable HTTP/2 support in Spring Boot, we can set the following:

    server.http2.enabled=true
    
  • 42
    How to change the port of the embedded Tomcat server?

    This could be achieved easily by making use of the application properties file. All you need to do is add a property of “server.port” and then assign the property to any port. 

  • 43
    What is an auto-configuration in Spring boot? 

    Usage of not required WAR files can be avoided by loading the default configurations based on the project you are working on. This is what auto-configuration in Spring Boot does.

  • 44
    What is Spring Boot Initializr ?

    Spring Boot Initializr is an API. It is used to quick start new Spring Boot Projects easily.

    This API can be downloaded from here.

    Develop application using Spring Boot Initializr with examples explained- here.

  • 45
    Why we need Spring Boot Initializr?

    Spring Boot Initilizr API is used to simplify the development of Spring Applications. It provides initial project structure and build scripts.

    Advantages of Spring Boot Initializr:

    • Reduces Development time
    • Increases Productivity
  • 46
    What is mean by spring batch?

    Spring Boot Batch provides code reusability which is important when working with large numbers of records, including transaction management, logging, skipping, job processing statistics, and job restarts.

  • 47
     Define apache freemarker.

    Freemarker is a Java-based template used to generate plain text, emails, HTML file, etc.

  • 48
     Explain caching.

    Caching is a memory are that temporary stores frequently accessed data that is otherwise expensive to get or compute.

  • 49
    Explain Docker in Spring Boot.

    It is a tool designed to create, deploy, and run a project by using containers.

  • 50
    What do you mean by hot-swapping in Spring Boot?

    It is a way to reload the changes without restarting Tomcat, or Jetty server. Eclipse and Many other IDEs support bytecode hot swapping. If you make any changes that don’t affect the method signature, it should reload without side effect.