In this post you will know the frequently asked Spring boot interview questions for freshers and experienced candidates. The Spring Boot is now the standard way to use Spring framework for Java development and almost all the companies are moving from the traditional way of using Spring Framework to more modern Spring Boot way. Gone are the days, where questions like have you used Spring Boot was asked to the developer
Spring Boot aims to simplify Java development with Spring by removing major pain points with respect to configuration, dependency management and ease of development.
1) What is Spring Boot?
Spring Boot is a Spring module which provides RAD (Rapid Application Development) feature to Spring framework.
It is used to create stand alone spring based application that you can just run because it needs very little spring configuration.
2) Why should use Spring Boot?
The advantages of Spring Boot are
- Reduce Developement, Testing time and efforts.
- Use of JavaConfig helps avoid usage of XML.
- Avoid lots of maven imports and the various version conflicts.
Spring Boot not only provides a lot of convenience by auto-configuration a lot of things for you but also improves the productivity because it lets you focus only on writing your business logic.
For example, you don't need to setup a Tomcat server to run your web application. You can just write code and run it as Java application because it comes with an embedded Tomcat server. You can also create a JAR file or WAR file for deployment based on your convenience.
In short, there are many reasons to use Spring Boot. In fact, it's now the standard way to develop Java application with Spring framework.
3)Which build tool have you used to develop Spring Boot Application ?
Spring Boot application can be developed using Maven as well as Gradle.
Spring Boot application using Maven
Spring Boot application using Gradle
4)How to create Spring Boot application using Maven?
There are multiple approaches to create Spring Boot project. We can use any of the following approach to create application.
- Spring Maven Project
- Spring Starter Project Wizard
- Spring Initializr
- Spring Boot CLI
5)What is Actuator in Spring Boot?
Spring boot actuator is one of the important feature in spring boot framework. Spring boot actuator helps you to access the current state of the running application in production environment. There are several metrics that has to be checked and monitored in the production environment. Even some external applications may be using those services to trigger the alert message to concerned person. Actuator module exposes set of REST endpoints that can be directly accessed as a HTTP URL to check the status.
6) Where do you define properties in Spring Boot application?
You can define both application and Spring boot related properties into a file called application.properties. You can create this file manually or you can use Spring Initializer to create this file, albeit empty.
You don't need to do any special configuration to instruct Spring Boot load this file. If it exists in classpath then Spring Boot automatically loads it and configure itself and application code according.
For example, you can use to define a property to change the embedded server port in Spring Boot, which is also our next question.
7) What embedded containers does Spring Boot support?
Spring Boot support three embedded containers: Tomcat, Jetty, and Undertow. By default, it uses Tomcat as embedded containers but you can change it to Jetty or Undertow.
8) Can you name some common Spring Boot Starter POMs?
Some of the most common Spring Boot Start dependencies or POMs are spring-boot-starter, spring-boot-starter-web, spring-boot-starter-test. You can use spring-boot-starter-web to enable Spring MVC in Spring Boot application.
9)Can you control logging with Spring Boot? How?
Yes, we can control logging with Spring Boot by specifying log levels on application.properties file. Spring Boot loads this file when it exists in the classpath and it can be used to configure both Spring Boot and application code.
Spring Boot uses Commons Logging for all internal logging and you can change log levels by adding following lines in the application.properties file:
10)What is the difference between an embedded container and a WAR?
The main difference between an embedded container and a WAR file is that you can Spring Boot application as a JAR from the command prompt without setting up a web server. But to run a WAR file, you need to first set up a web server like Tomcat which has Servlet container and then you need to deploy WAR there