← Home
☕Java Developer Interview Questions — Fresher to 5 YOEJava Dev InterviewNEW
🚦

Spring Boot Fundamentals

Auto-configuration, starters, profiles · 17 questions

1

What is Spring Boot, and how is it different from the Spring Framework?

Must Know🌱 Fresher

The Spring Framework is powerful but historically required a lot of manual setup — XML or Java configuration for the web container, the dependency versions to pick, the boilerplate to wire a DispatcherServlet. Spring Boot is built on top of Spring and removes that setup tax: it provides auto-configuration (sensible defaults based on what's on the classpath), starter dependencies (curated, compatible dependency bundles), an embedded server (no separate Tomcat install needed — just run the jar), and production-ready features (Actuator) out of the box. Spring Boot doesn't replace Spring's core concepts (beans, DI, AOP) — it makes getting a Spring application running dramatically faster.

Spring Boot
2

What is Spring Boot auto-configuration, and how does it work?

Must Know🌱 Fresher

Auto-configuration automatically registers beans based on what it finds on the classpath and what beans you've already defined yourself — without you writing any explicit configuration. For example, adding spring-boot-starter-data-jpa to your dependencies is enough for Spring Boot to detect Hibernate + a JDBC driver on the classpath and auto-configure a DataSource, an EntityManagerFactory, and a TransactionManager for you.

🚦 How auto-configuration decides
@SpringBootApplication
   |
   +-- @EnableAutoConfiguration
           |
           v
   Scans META-INF/spring/....AutoConfiguration.imports
           |
           v
   For each candidate config class, evaluate @Conditional* annotations:
     @ConditionalOnClass(DataSource.class)       -- is this on the classpath?
     @ConditionalOnMissingBean(DataSource.class) -- did the user already define one?
           |
           v
   Only conditions that pass get their beans registered

Crucially, auto-configuration always backs off if you've defined your own bean of the same type — see the @ConditionalOnMissingBean question for how that works.

Spring BootAuto-configuration
3

What are Spring Boot starters?

Must Know🌱 Fresher

Starters are curated dependency bundles (spring-boot-starter-*) that pull in everything typically needed for one concern, at versions Spring Boot has already tested together — so you don't have to hunt down and hand-pick compatible versions of a dozen individual libraries yourself.

Common starterstext
spring-boot-starter-web       -- Spring MVC + embedded Tomcat + Jackson (REST APIs)
spring-boot-starter-data-jpa  -- Spring Data JPA + Hibernate
spring-boot-starter-security  -- Spring Security
spring-boot-starter-test      -- JUnit, Mockito, AssertJ, Spring Test
spring-boot-starter-actuator  -- production monitoring endpoints
Spring BootStarters
4

What does @SpringBootApplication actually do?

Must Know🌱 Fresher

@SpringBootApplication is a convenience meta-annotation that bundles three separate annotations into one:

  • @SpringBootConfiguration — a specialization of @Configuration, marking this class as a source of bean definitions.
  • @EnableAutoConfiguration — turns on Spring Boot's auto-configuration mechanism.
  • @ComponentScan — tells Spring to scan this class's package (and sub-packages) for @Component/@Service/@Repository/@Controller classes.

This is why the main application class is conventionally placed at the root package of the project — component scanning only looks downward from wherever this annotation lives.

Spring Boot
5

What are Spring profiles, and how do you activate them?

Must Know🌱 Fresher

Profiles let you define environment-specific beans and configuration — application-dev.yml, application-prod.yml — and switch between them without changing code. A bean can be scoped to a profile with @Profile("dev"); the active profile is set via the spring.profiles.active property (environment variable, command-line arg, or the base application.yml).

Activating a profiletext
java -jar app.jar --spring.profiles.active=prod
# or
SPRING_PROFILES_ACTIVE=prod java -jar app.jar
Spring BootProfiles
6

What is the difference between application.properties and application.yml?

Important🌱 Fresher

Both configure the same things — server port, datasource URL, logging levels, custom properties — just in different syntax. .properties is flat key=value pairs; .yml (YAML) supports nested structures natively, which reads more cleanly for deeply grouped configuration (and is required for some structures like a list of maps). YAML is whitespace/indentation-sensitive, which trips people up; .properties has no such fragility but gets repetitive for deeply nested keys.

Same config, both formatstext
# application.properties
spring.datasource.url=jdbc:postgresql://localhost/db
spring.datasource.username=app

# application.yml
spring:
  datasource:
    url: jdbc:postgresql://localhost/db
    username: app
Spring BootConfiguration
7

How does Spring Boot’s embedded server (Tomcat/Jetty/Undertow) work?

Important📊 Mid

Instead of building a WAR and deploying it to an externally installed Tomcat, Spring Boot bundles the servlet container (Tomcat by default, Jetty or Undertow as swap-in alternatives) directly inside the runnable JAR. Starting the application programmatically starts an embedded server instance on a configured port — so "running the app" is just java -jar app.jar, with no separate server installation, configuration, or deployment step. This is a big part of why Spring Boot apps are so friendly to containerized deployment (Docker) — the artifact is fully self-contained.

Spring BootEmbedded Server
8

What is @Value, and what is the property source precedence order in Spring Boot?

Important📊 Mid

@Value("${some.property}") injects a single configuration value directly into a field — a lighter-weight alternative to binding a whole @ConfigurationProperties class when you just need one or two values.

Spring Boot reads configuration from many sources, applying them in a defined precedence order (highest wins on conflict) — roughly, from highest to lowest priority: command-line arguments, JVM system properties, OS environment variables, profile-specific application-{profile}.yml, then the base application.yml, then @PropertySource-declared files, then defaults set in code. This lets ops override a single value at deploy time (e.g. an environment variable) without touching any config file baked into the jar.

Spring BootConfiguration
9

What is Spring Boot Actuator?

Important🌱 Fresher

Actuator adds production-monitoring endpoints to a Spring Boot app with almost no setup — just add the spring-boot-starter-actuator dependency. It exposes endpoints like /actuator/health (is the app and its dependencies — DB, disk space — healthy?), /actuator/metrics (JVM memory, request counts, custom metrics), /actuator/env (resolved configuration properties), and /actuator/info — the exact set of endpoints exposed over HTTP is configurable (most are disabled by default except health/info, since some leak sensitive internal detail).

Spring BootActuator
10

What is @ConfigurationProperties, and how does it compare to @Value?

Important📊 Mid

@Value injects one property at a time — fine for a single field, awkward once you have a whole related group of settings. @ConfigurationProperties binds a whole prefix of properties onto a strongly-typed class in one shot, including nested objects and lists, with IDE auto-complete support and centralized validation (via Bean Validation annotations on the properties class).

@ConfigurationProperties binds a whole groupjava
@ConfigurationProperties(prefix = "app.mail")
record MailProperties(String host, int port, @NotBlank String from) { }

// application.yml:
// app.mail.host: smtp.example.com
// app.mail.port: 587
// app.mail.from: noreply@example.com

@Service
class MailService {
    MailService(MailProperties mailProperties) { ... } // fully populated, type-safe object
}
Spring BootConfiguration
11

How do you document a REST API in Spring Boot with Swagger/OpenAPI?

Important🌱 Fresher

Adding springdoc-openapi-starter-webmvc-ui (the modern successor to the older springfox library) automatically scans your controllers and generates an OpenAPI specification — a machine-readable description of every endpoint, its parameters, and response shapes — plus a browsable Swagger UI page (typically at /swagger-ui.html) where you can try requests directly from the browser. Annotations like @Operation, @Parameter, and @Schema let you add human-readable descriptions on top of what's inferred automatically from your method signatures and DTOs.

Spring BootAPI Documentation
12

What does @Async do, and what are its limitations?

Important📊 Mid

@Async on a method makes Spring run it on a separate thread (from a configurable task executor) instead of the caller's thread — the call returns immediately, letting the caller move on rather than block waiting for that method to finish.

Fire-and-forget or async with a resultjava
@EnableAsync // required on a @Configuration class to activate @Async processing
@Service
class NotificationService {
    @Async
    void sendEmail(String to) { ... } // caller doesn't wait

    @Async
    CompletableFuture<Report> generateReport() { ... } // caller can await/compose the result later
}

Limitations worth knowing: it only works through the same Spring AOP proxy mechanism as @Transactional, so self-invocation bypasses it just like the transactional self-invocation gotcha; exceptions thrown inside a void @Async method are simply logged, not propagated to the caller (since the caller already moved on); and it needs @EnableAsync explicitly enabled to take effect at all.

Spring BootAsync
13

How does Spring’s caching abstraction work (@Cacheable, @CacheEvict, @CachePut)?

Important📊 Mid

Spring's caching abstraction (@EnableCaching + a cache provider like Caffeine or Redis) lets you cache a method's return value declaratively, without hand-writing cache-lookup logic inside the method itself.

Cache annotationsjava
@Cacheable("users")                 // cache the result, keyed by the argument(s)
User findById(Long id) { ... }        // subsequent calls with the same id skip the method body entirely

@CachePut("users")                    // always runs the method, but updates the cache with the result
User update(User user) { ... }

@CacheEvict("users")                  // removes the entry so the next read is fresh
void delete(Long id) { ... }

Like @Transactional and @Async, this works via an AOP proxy — the same self-invocation limitation applies, and the cache key defaults to the method's arguments unless you customize it with a SpEL key expression.

Spring BootCaching
14

How do @ConditionalOnClass and @ConditionalOnMissingBean let auto-configuration back off when you define your own bean?

Advanced📊 Mid

Every auto-configuration class is guarded by @Conditional* annotations that the container evaluates before registering its beans. Two of the most important:

  • @ConditionalOnClass(SomeClass.class) — only apply this auto-configuration if a given class is present on the classpath (e.g. only configure a DataSource auto-config if a JDBC driver is actually there).
  • @ConditionalOnMissingBean(SomeType.class) — only register this auto-configured bean if the user hasn't already defined one of that type themselves.

This second one is exactly why you can override any auto-configured bean simply by declaring your own @Bean of the same type — auto-configuration always checks first and steps aside, rather than clobbering your explicit configuration.

Spring BootAuto-configuration
15

What is the difference between CommandLineRunner and ApplicationRunner?

Optional🌱 Fresher

Both are functional interfaces you implement (or declare as a @Bean lambda) to run code right after the Spring application context has started — useful for startup tasks (seeding data, warming a cache). The only difference is the argument type each receives: CommandLineRunner.run(String... args) gets the raw command-line arguments as a plain string array, while ApplicationRunner.run(ApplicationArguments args) wraps them in a richer object that distinguishes named options (--server.port=8080) from plain positional arguments.

Spring Boot
16

What is Spring Boot DevTools?

Optional🌱 Fresher

DevTools is a development-time-only dependency that improves the local dev loop: it automatically restarts the application when it detects a classpath change (much faster than a full manual restart, since it reuses a separate classloader for unchanged libraries), disables template/view caching so edits show up immediately, and enables a LiveReload trigger for the browser. It's automatically excluded from a production build/repackaged jar, so there's no need to manually strip it before deploying.

Spring BootDevTools
17

What does @Scheduled do, and what do cron/fixedRate/fixedDelay mean?

Optional🌱 Fresher

@Scheduled (with @EnableScheduling on a configuration class) runs a method automatically on a recurring schedule, without any external cron daemon or job scheduler.

Scheduling optionstext
@Scheduled(fixedRate = 60000)   -- run every 60s, measured from the start of the previous run
@Scheduled(fixedDelay = 60000)  -- run every 60s, measured from the END of the previous run
@Scheduled(cron = "0 0 * * * *") -- run on a cron expression (here: top of every hour)

fixedDelay guarantees a gap between executions (safer if a run can occasionally take longer than the interval); fixedRate can start overlapping runs if one execution runs long. By default, all @Scheduled methods share a single thread unless you configure a dedicated task scheduler with a larger pool.

Spring BootScheduling