Top 10 Spring Boot Interview Questions Every Backend Developer Must Know
This article presents the ten most frequently asked Spring Boot interview questions, covering annotations, package exclusion, auto‑configuration control, Actuator features, initializer usage, embedded Tomcat customization, and how to disable the default web server, providing concise answers and code examples for each.
In this article we discuss the ten most common Spring Boot interview questions, which are increasingly important in the job market.
1. What does @SpringBootApplication do?
According to the Spring Boot documentation, the @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes. Spring Boot lets developers use a single annotation instead of multiple ones, though each can be used separately as needed.
2. How to exclude any package without using a basePackages filter?
You can filter arbitrary packages in various ways. Spring Boot provides a convenient option using the @SpringBootApplication annotation’s exclude attribute. Example:
@SpringBootApplication(exclude={Employee.class})
public class FooAppConfiguration {}3. How to disable a specific auto‑configuration class?
You can use the @EnableAutoConfiguration annotation’s exclude attribute:
//By using "exclude"
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})If the class is not on the classpath, you can use the excludeName attribute with the fully qualified name:
//By using "excludeName"
@EnableAutoConfiguration(excludeName={Foo.class})Spring Boot also supports the spring.autoconfigure.exclude property in application.properties to list classes to exclude, separated by commas.
//By using property file
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration4. What is Spring Actuator and what are its benefits?
Spring Actuator provides production‑ready features such as bean inspection, request mapping, CPU usage, health checks, and metrics. It exposes a set of REST endpoints that can be secured with Spring Security or a custom RequestMatcher.
5. How to enable or disable Actuator?
Enable Actuator by adding the spring-boot-starter-actuator dependency. If you do not want Actuator, simply omit the dependency.
Maven dependency:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>6. What is Spring Initializer?
Spring Initializer is a web application that generates a Spring Boot project with all necessary starter dependencies, helping you quickly set up a proper project structure.
7. What does the shutdown endpoint do in Actuator?
The shutdown endpoint allows the application to terminate gracefully. It is disabled by default and can be enabled by setting management.endpoint.shutdown.enabled=true in application.properties, but should be used with caution.
8. Can the embedded Tomcat server port be changed?
Yes. Set server.port in application.properties, e.g., server.port=8081 . Setting server.port=0 lets Spring Boot pick a random available port.
9. Can the embedded Tomcat server be replaced?
Yes. Replace it with another server by adding the appropriate starter dependency, such as spring-boot-starter-jetty or spring-boot-starter-undertow.
10. Can the default web server be disabled?
Spring Boot allows disabling the web server by setting spring.main.web-application-type=none in application.properties.
Wish you all the best!
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
