Spring Boot Interview Questions(2025)
In this post we will look at Spring Boot Interview questions. Examples are provided with explanation.
- What is Spring Boot?
- What are advantages of Spring Boot?
- Which build tool have you used to develop Spring Boot Application?
- What is JavaConfig?
- How to reload my changes on Spring Boot without having to restart server?
- What is Actuator in Spring Boot?
- How to implement JWT authentication for Spring Boot Application?
- How to deploy Spring Boot application as a WAR?
- What is Docker? How to deploy Spring Boot Applications to Docker?
- How to disable Actuator endpoint security in Spring Boot?
- How to run Spring boot application to custom port?
- What is ELK stack?How to use it with Spring Boot?
- Have you written Test cases using Spring Boot?
- What is YAML?
- How to implement security for Spring boot application?
- Have you integrated Spring Boot and ActiveMQ?
- Have you integrated Spring Boot and Apache Kafka?
- How to implement Pagination and Sorting with Spring Boot?
- What is Swagger? Have you implemented it using Spring Boot?
- What is Spring Profiles? How do you implement it using Spring Boot?
- What is Spring Batch? How do you implement it using Spring Boot?
- What is FreeMarker Template? How do you implement it using Spring Boot?
- How to implement Exception Handling using Spring Boot?
- What is caching? Have you used any caching framework with Spring Boot?
- Have you exposed a SOAP webservice endpoint using Spring Boot?
- How did you perform database operations using Spring Boot?
- How to develop a full stack application using Spring Boot and Angular?
- How to upload a file using Spring?
- How to implement interceptors with Spring Boot?
- Which all starter maven dependencies have you used?
- What is CSRF attack? How to enable CSRF protection against it?
- How to use Form Login Authentication using Spring Boot?
- When will you use WebSockets? How to implement it using Spring Boot?
- What is AOP? How to use it with Spring Boot?
- What is Apache Kafka? How to integrate it with Spring Boot?
- How can we monitor all the Spring Boot Microservices?
- Have you used any Spring Cloud Components with Spring Boot?
- How to deploy Spring Boot Application to Pivotal Cloud Foundry(PCF)?
- How to deploy Spring Boot + MySQL Application to Pivotal Cloud Foundry(PCF)?
- How to deploy Spring Boot + RabbitMQ Application to Pivotal Cloud Foundry(PCF)?
- What is JWT ? How to implement it using Spring Boot Security?
- How to implement distributed logging for microservices?
- What is Hashicorp Valut? How to use it with microservices?
What is Spring Boot?
Over the years spring has become more and more complex as new functionalities have been added. Just visit the page-https://spring.io/projects and we will see all the spring projects we can use in our application for different functionalities. If one has to start a new spring project we have to add build path or add maven dependencies, configure application server, add spring configuration . So a lot of effort is required to start a new spring project as we have to currently do everything from scratch. Spring Boot is the solution to this problem. Spring boot has been built on top of existing spring framework. Using spring boot we avoid all the boilerplate code and configurations that we had to do previously. Spring boot thus helps us use the existing Spring functionalities more robustly and with minimum efforts.More details and miscellaneous examples
What are advantages of 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.
- Provide Opinionated Development approach.
- Quick start to development by providing defaults.
- No Separate Web Server Needed.Which means that you no longer have to boot up Tomcat, Glassfish, or anything else.
- Requires less configuration-Since there is no web.xml file. Simply add classes annotated with@Configuration and then you can add methods annotated with@Bean, and Spring will automagically load up the object and manage it like it always has. You can even add @Autowired to the bean method to have Spring autowire in dependencies needed for the bean.
- Environment Based Configuration-Using these properties, you can pass into the application which environment you are using with:-Dspring.profiles.active={enviornment}. Spring will then load up the subsequent application properties file at (application-{environment}.properties) after loading up the main application properties file.
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
What is JavaConfig?
Spring JavaConfig is a product of the Spring community that provides a pure-Java approach to configuring the Spring IoC Container. It thus helps avoid using XML configurations. The advantages of using JavaConfig areThe advantages of JavaConfig are
- Object-oriented configuration. Because configurations are defined as classes in JavaConfig, users can take full advantage of object-oriented features in Java. One configuration class may subclass another, overriding its @Bean methods, etc.
- Reduced or eliminated XML configuration. The benefits of externalized configuration based on the principles of dependency injection have been proven. However, many developers would prefer not to switch back and forth between XML and Java. JavaConfig provides developers with a pure-Java approach to configuring the Spring container that is conceptually similar to XML configuration. It is technically possible to configure the container using only JavaConfig configuration classes, however in practice many have found it ideal to mix-and-match JavaConfig with XML.
- Type-safe and refactoring-friendly. JavaConfig provides a type-safe approach to configuring the Spring container. Thanks to Java 5.0's support for generics, it is now possible to retrieve beans by type rather than by name, free of any casting or string-based lookups.
How to reload my changes on Spring Boot without having to restart server?
This can be achieved using DEV Tools. With this dependency any changes you save, the embedded tomcat will restart. Spring Boot has a Developer tools (DevTools) module which helps to improve the productivity of developers. One of the key challenge for the Java developers is to auto deploy the file changes to server and auto restart the server. Developers can reload changes on Spring Boot without having to restart my server. This will eliminates the need for manually deploying the changes every time. Spring Boot doesnt have this feature when it has released its first version. This was a most requested features for the developers. The module DevTools does exactly what is needed for the developers. This module will be disabled in the production environment. It also provides H2-database console for better testing the application. The following dependency is used<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>The DevTool dependency usage for autorestart and H2 DB console is illustrated in this example
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.How to implement JWT authentication for Spring Boot Application?
We will be implementing Spring Boot +JWT + MYSQL Hello World ExampleJWT stands for JSON Web Token. JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. The client will need to authenticate with the server using the credentials only once. During this time the server validates the credentials and returns the client a JSON Web Token(JWT). For all future requests the client can authenticate itself to the server using this JSON Web Token(JWT) and so does not need to send the credentials like username and password.
How to deploy Spring Boot application as a WAR?
Spring Boot WAR DeploymentWhat is Docker? How to deploy Spring Boot Applications to Docker?
What is DockerDeploying Spring Based WAR Application to Docker
Deploying Spring Based JAR Application to Docker
How to disable Actuator endpoint security in Spring Boot?
By default all sensitive HTTP endpoints are secured such that only users that have an ACTUATOR role may access them. Security is enforced using the standard HttpServletRequest.isUserInRole method.We can disable security using -
management.security.enabled=false
It is suggested to disable security only if the actuator endpoints are accessed behind firewall.
How to run Spring boot application to custom port?
In order to run a spring boot application on a custom port you can specify the port in application.properties.server.port=8090
What is ELK stack?How to use it with Spring Boot?
The ELK Stack consists of three open-source products - Elasticsearch, Logstash, and Kibana from Elastic.
-
Elasticsearch is a NoSQL database that is based on
the Lucene search engine.