Spring Boot Concepts
Spring Boot Concepts Interview with follow-up questions
1. What is the role of @EnableAutoConfiguration annotation in Spring Boot?
@EnableAutoConfiguration switches on Spring Boot's auto-configuration: it tells Boot to inspect the classpath, existing beans, and properties, and automatically configure the beans your app likely needs (DataSource, MVC, Jackson, etc.) — sparing you the manual setup.
You rarely write it directly, because it's bundled inside @SpringBootApplication, which combines three annotations:
@SpringBootApplication // = @Configuration + @ComponentScan + @EnableAutoConfiguration
class App { ... }
How it operates: it loads auto-configuration classes listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (the modern replacement for the legacy spring.factories entry), each guarded by @Conditional checks (@ConditionalOnClass, @ConditionalOnMissingBean, …) so a configuration applies only when appropriate and backs off if you've defined your own bean.
Points worth making: you can exclude unwanted auto-config via @SpringBootApplication(exclude = DataSourceAutoConfiguration.class), and inspect what fired with the --debug conditions report. The takeaway: @EnableAutoConfiguration is the trigger that makes Boot "just work," while remaining fully overridable by your own configuration.
Follow-up 1
How does @EnableAutoConfiguration work internally?
Internally, the @EnableAutoConfiguration annotation works by using Spring Boot's auto-configuration mechanism. When this annotation is present, Spring Boot will scan the classpath for libraries and frameworks and look for specific configuration classes known as auto-configuration classes. These auto-configuration classes are responsible for configuring beans and other components based on the presence of certain conditions. Spring Boot uses a combination of classpath scanning, conditional annotations, and property-based configuration to determine which auto-configuration classes to apply.
Follow-up 2
What are the alternatives to @EnableAutoConfiguration?
The alternatives to @EnableAutoConfiguration in Spring Boot are:
@Import: Instead of relying on the automatic configuration provided by @EnableAutoConfiguration, you can manually import specific configuration classes using the @Import annotation. This gives you more control over the configuration process.
@ComponentScan: This annotation allows you to specify the packages to scan for components and beans. By using @ComponentScan, you can manually configure the application context and selectively include or exclude specific components.
XML Configuration: If you prefer XML-based configuration, you can use the traditional Spring XML configuration files to define beans and their dependencies. However, this approach is less commonly used in Spring Boot applications.
Follow-up 3
Can you give an example of when you would use this annotation?
Sure! One example of when you would use the @EnableAutoConfiguration annotation is when you want to quickly bootstrap a Spring Boot application with sensible default configurations. By adding this annotation to the main configuration class, Spring Boot will automatically configure the application context based on the dependencies and classpath. This can save you a lot of time and effort in setting up the initial configuration of your application.
Follow-up 4
What are the potential issues that might arise when using @EnableAutoConfiguration?
While the @EnableAutoConfiguration annotation provides a convenient way to configure a Spring Boot application, there are a few potential issues that you should be aware of:
Conflicting Configurations: If multiple auto-configuration classes define conflicting configurations, it can lead to unexpected behavior. In such cases, you may need to manually exclude certain auto-configuration classes or provide your own custom configuration.
Classpath Scanning Overhead: Scanning the classpath for auto-configuration classes can introduce some overhead, especially in large applications with many dependencies. This can impact the startup time of the application.
Limited Control: While @EnableAutoConfiguration provides a lot of convenience, it may limit your control over the configuration process. If you require fine-grained control over the configuration, you may need to use alternative approaches like @Import or @ComponentScan.
2. How does Spring Boot simplify the dependency management?
Spring Boot simplifies dependency management two ways:
- Starters — curated dependency bundles named by capability (
spring-boot-starter-web,-data-jpa,-security,-test). Adding one pulls in everything needed for that feature, already tested to work together, so you don't hand-pick individual libraries. - Dependency/version management — the Spring Boot BOM (bill of materials), inherited via the parent POM or Gradle plugin, pins compatible versions of Boot's dependencies. You usually declare a starter without a version, and Boot supplies a consistent, conflict-free set.
org.springframework.boot
spring-boot-starter-web
The benefit interviewers want named: this eliminates "dependency hell" — mismatched transitive versions of Spring, Jackson, Hibernate, etc. You can still override a managed version when needed, and spring-boot-starter-parent (or io.spring.dependency-management in Gradle) provides the BOM. A current note: a major version bump (e.g. Boot 3 → 4) moves the whole managed set forward together (including the javax → jakarta shift in Boot 3), which is exactly why centralized version management matters.
Follow-up 1
What is a starter dependency in Spring Boot?
A starter dependency in Spring Boot is a pre-configured set of dependencies that are commonly used together to build a specific type of application. These starter dependencies provide a convenient way to include all the necessary dependencies for a particular functionality or technology stack. For example, the 'spring-boot-starter-web' dependency includes all the necessary dependencies for building web applications with Spring Boot.
Follow-up 2
How does Spring Boot handle version conflicts in dependencies?
Spring Boot uses a dependency management mechanism to handle version conflicts in dependencies. When you include a starter dependency in your project, Spring Boot will automatically manage the versions of the transitive dependencies. It ensures that all the dependencies in your project are compatible with each other by using a predefined set of compatible versions. If there is a version conflict, Spring Boot will resolve it by selecting the most appropriate version based on the compatibility rules defined in its dependency management.
Follow-up 3
Can you provide an example of a common starter dependency?
One example of a common starter dependency in Spring Boot is the 'spring-boot-starter-data-jpa' dependency. This starter dependency includes all the necessary dependencies for using the Java Persistence API (JPA) with Spring Boot, such as Hibernate, Spring Data JPA, and the necessary database drivers. By including this starter dependency in your project, you can easily set up and configure JPA-based data access in your Spring Boot application.
Follow-up 4
What are the advantages of using starter dependencies?
There are several advantages of using starter dependencies in Spring Boot:
Simplified dependency management: Starter dependencies provide a convenient way to include all the necessary dependencies for a specific functionality or technology stack. This simplifies the dependency management process and reduces the chances of version conflicts.
Opinionated defaults: Starter dependencies come with pre-configured defaults and auto-configuration. This allows you to quickly get started with common use cases without having to manually configure each individual dependency.
Rapid application development: By using starter dependencies, you can quickly bootstrap a Spring Boot application with the necessary dependencies and configurations. This enables rapid application development and reduces the time required to set up a new project.
Ecosystem integration: Starter dependencies are designed to work seamlessly with other Spring Boot features and libraries. They are part of the larger Spring ecosystem and provide integration with other Spring projects, such as Spring Data, Spring Security, and Spring Cloud.
3. What is the purpose of the Spring Boot Actuator?
The Actuator provides production-ready operational features — it exposes endpoints that let you monitor and manage a running app: health, metrics, configuration, and more. It turns a Boot app into something observable and operable without writing that plumbing yourself.
What it exposes:
/actuator/health— app and dependency health (DB, disk, broker), with liveness/readiness probes for Kubernetes./actuator/metrics+/actuator/prometheus— Micrometer metrics (JVM, HTTP, custom) for Prometheus/Grafana./actuator/info,/actuator/loggers(change log levels live),/actuator/env,/actuator/heapdump,/actuator/threaddump.
management.endpoints.web.exposure.include: health,metrics,prometheus
The points interviewers reward: by default only health/info are web-exposed — you opt the rest in and must secure the sensitive ones (they can reveal env/config). Actuator + Micrometer is the backbone of Boot's observability (metrics + distributed tracing via OpenTelemetry), and its health endpoints integrate directly with container orchestration. It's the standard answer for "how do you monitor a Spring Boot app in production."
Follow-up 1
What are some of the endpoints provided by Spring Boot Actuator?
Spring Boot Actuator provides several endpoints, including:
/health: Provides information about the application's health status./info: Displays arbitrary application information./metrics: Exposes metrics about the application, such as memory usage, CPU usage, and request counts./loggers: Allows you to view and modify the logging configuration./env: Provides information about the application's environment variables./trace: Shows the recent HTTP requests handled by the application./beans: Displays a list of all Spring beans in the application context./mappings: Shows the mappings between request URLs and the methods that handle them.
These are just a few examples, and there are many more endpoints available.
Follow-up 2
How can you customize the Actuator's endpoints?
You can customize the Actuator's endpoints by modifying the management.endpoints.web.base-path property in your application's configuration file. By default, the Actuator endpoints are prefixed with /actuator, but you can change this prefix to a different value if desired.
For example, to change the base path to /management, you can add the following line to your application.properties file:
management.endpoints.web.base-path=/management
After making this change, the Actuator endpoints will be accessible under the /management path instead of /actuator.
Follow-up 3
How can you secure Actuator endpoints?
You can secure Actuator endpoints by configuring Spring Security in your application. By default, Actuator endpoints are not secured, which means anyone can access them. However, you can restrict access to these endpoints by adding appropriate security configurations.
To secure Actuator endpoints, you can use Spring Security's antMatchers method to specify which endpoints should be protected and define the required authentication and authorization rules.
For example, to require authentication for all Actuator endpoints, you can add the following configuration to your application:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/actuator/**").authenticated()
.anyRequest().permitAll()
.and()
.httpBasic();
}
}
This configuration ensures that all Actuator endpoints require authentication, while allowing unrestricted access to other parts of the application.
Follow-up 4
What kind of information can you get from the Actuator's health endpoint?
The Actuator's health endpoint provides information about the application's health status. It returns a JSON response that includes details such as the status of various components and dependencies used by the application.
The health endpoint can return different statuses, including:
UP: Indicates that the application is running and all components are functioning correctly.DOWN: Indicates that one or more components are not functioning correctly.OUT_OF_SERVICE: Indicates that the application is temporarily out of service.UNKNOWN: Indicates that the health status is unknown.
In addition to the overall health status, the health endpoint may also provide additional details about the health of specific components, such as database connections, message queues, and external services.
4. How does Spring Boot handle application properties?
Spring Boot externalizes configuration so you don't hard-code values. The primary source is application.properties or application.yml (on the classpath or beside the jar), holding settings like datasource URLs, ports, and log levels.
You consume properties in three main ways:
@Value("${server.port}")— inject a single value.@ConfigurationProperties(prefix = "app")— bind a group of properties to a typed POJO (preferred for structured config; supports validation).- The
EnvironmentAPI for programmatic access.
@ConfigurationProperties(prefix = "mail")
record MailProps(String host, int port) {}
The points that make a strong answer: Boot merges many sources in a defined precedence order (command-line args > env vars > profile files > application.yml > defaults), which is what lets environment variables override file config in containers — essential for 12-factor apps. Profiles (application-prod.yml, spring.profiles.active=prod) provide per-environment config, and relaxed binding maps MY_APP_HOST → my.app.host. For secrets, use env vars / a secrets manager / Spring Cloud Config rather than committing them. Prefer type-safe @ConfigurationProperties over scattered @Values.
Follow-up 1
What are the different ways to specify application properties in Spring Boot?
There are several ways to specify application properties in Spring Boot:
Using the
application.propertiesorapplication.ymlfile: Spring Boot automatically loads properties from these files located in the classpath.Using command-line arguments: Properties can be passed as command-line arguments using the
--property=valuesyntax.Using environment variables: Spring Boot can read properties from environment variables.
Using the
@Valueannotation: Properties can be injected into beans using the@Valueannotation.Using the
@ConfigurationPropertiesannotation: Properties can be bound to a bean using the@ConfigurationPropertiesannotation.
Follow-up 2
How can you use @Value annotation to access properties?
The @Value annotation can be used to inject properties into beans. It can be used to access properties from the application.properties or application.yml file, as well as from command-line arguments and environment variables.
Here's an example of using the @Value annotation to access a property:
@Value("${my.property}")
private String myProperty;
Follow-up 3
What is the role of @ConfigurationProperties annotation?
The @ConfigurationProperties annotation is used to bind properties to a bean. It allows you to map properties from the application.properties or application.yml file to fields of a bean. This annotation is particularly useful when you have a large number of properties to configure.
Here's an example of using the @ConfigurationProperties annotation:
@ConfigurationProperties(prefix = "my")
public class MyProperties {
private String property1;
private String property2;
// getters and setters
}
Follow-up 4
How does Spring Boot handle property resolution order?
Spring Boot follows a specific order when resolving properties:
Command-line arguments: Properties passed as command-line arguments take the highest precedence.
Java System properties: Properties set as Java System properties.
OS environment variables: Properties set as environment variables.
application.propertiesorapplication.ymlfile: Properties defined in theapplication.propertiesorapplication.ymlfile.Default properties: Spring Boot provides a set of default properties that are applied if no other properties are specified.
It's important to note that properties with higher precedence override properties with lower precedence.
5. What is the role of the SpringApplication class in a Spring Boot application?
SpringApplication is the class that bootstraps and launches a Spring Boot app. Calling SpringApplication.run(App.class, args) does the heavy lifting of startup:
- Creates the appropriate
ApplicationContext(servlet, reactive, or none, inferred from the classpath). - Triggers component scanning and auto-configuration.
- Loads externalized configuration and activates profiles.
- Starts the embedded web server (if it's a web app).
- Fires lifecycle events and runs any
CommandLineRunner/ApplicationRunnerbeans.
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
Points worth adding: you can customize it via the SpringApplicationBuilder or by configuring a SpringApplication instance (banner, listeners, default properties, web application type, lazy init). It returns a ConfigurableApplicationContext you can use or close. The takeaway: SpringApplication is the single entry point that wires the entire Boot startup sequence — from context creation through auto-configuration to a running server — so main stays a one-liner.
Follow-up 1
What happens when you run a SpringApplication?
When you run a SpringApplication, it performs the following steps:
- It creates an instance of the Spring application context.
- It applies any necessary configuration to the application context, such as registering beans and configuring properties.
- It starts the embedded web server if the application is a web application.
- It runs the application by invoking the
runmethod on the application context.
Follow-up 2
How can you customize SpringApplication?
You can customize the behavior of a SpringApplication by:
- Modifying the application's configuration properties in the
application.propertiesorapplication.ymlfile. - Adding custom beans or components to the application context by using the
@Configurationand@Componentannotations. - Implementing the
SpringApplicationRunListenerinterface to listen for application events and perform custom actions. - Using the
SpringApplication.setDefaultPropertiesmethod to set default properties for all SpringApplication instances.
Follow-up 3
What are the different ways to bootstrap a Spring Application using SpringApplication?
There are several ways to bootstrap a Spring Application using SpringApplication:
- Using the
SpringApplication.run(Class> primarySource, String... args)method, whereprimarySourceis the primary source class (usually the main class) andargsare the command line arguments. - Using the
SpringApplication.run(String... args)method, whereargsare the command line arguments and the primary source class is inferred from the stack trace. - Using the
SpringApplication.run(Class>[] primarySources, String... args)method, whereprimarySourcesis an array of primary source classes andargsare the command line arguments.
Follow-up 4
How does SpringApplication handle application arguments?
SpringApplication handles application arguments by parsing them and making them available as beans in the application context. The arguments can be accessed using the @Value annotation or by injecting the ApplicationArguments bean. SpringApplication also provides utility methods to retrieve the arguments as a string array or as a list of strings.
Live mock interview
Mock interview: Spring Boot Concepts
- Read your scene and goals
- Talk it out; goals tick off live
- Get a score and stronger lines
Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.