skip to content

Spring Boot

The opinionated layer on top of Spring: auto-configuration, starters, externalized configuration, the SpringApplication lifecycle, embedded servers and packaging. Interviewers ask about Boot to find out whether you can explain its conventions or merely rely on them.

part ofSpring Frameworkoverview, primer and where to startread it →
on this pageshow

explore

questions

155 · 6 sections

What are @ConditionalOnClass and @ConditionalOnMissingClass, and why does Spring Boot auto-configuration rely on them?

level: juniorimportance: must knowfreq 70%
basics
~10 s

@ConditionalOnClass makes a bean/config load only if a named class is on the classpath; @ConditionalOnMissingClass only if it's absent. Boot uses them so auto-config activates just when the relevant library is present.

open as a page

What is a custom auto-configuration in Spring Boot, and how do you register it so Spring Boot picks it up automatically?

level: juniorimportance: must knowfreq 55%
basics
~10 s

A configuration class annotated with @AutoConfiguration that defines @Bean methods. You register it by listing its full class name in the file META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports so Spring Boot loads it on startup.

open as a page

What is @EnableAutoConfiguration and how does it end up on your application?

level: juniorimportance: must knowfreq 78%
basics
~10 s

@EnableAutoConfiguration tells Spring Boot to automatically configure beans based on what's on the classpath. You rarely write it directly because @SpringBootApplication already includes it.

open as a page

Explain @ConditionalOnProperty: its attributes (prefix, name, havingValue, matchIfMissing) and exactly when it matches.

level: middleimportance: must knowfreq 68%
basics
~20 s

@ConditionalOnProperty enables config based on a configuration property. It matches when the property (prefix + name) equals havingValue. matchIfMissing=true makes it match even when the property is absent, so a feature can be on by default.

open as a page

Why do @Bean methods in an auto-configuration almost always use @ConditionalOnMissingBean, and how do the conditional guards let a library back off?

level: middleimportance: must knowfreq 50%
basics
~20 s

@ConditionalOnMissingBean means 'only create this bean if the application hasn't already defined one.' It lets the library provide a sensible default while letting the app override it just by declaring its own bean of that type.

open as a page

What is the spring-boot-dependencies BOM and what problem does it solve?

level: juniorimportance: must knowfreq 70%
basics
~10 s

spring-boot-dependencies is a BOM (Bill of Materials): a special POM listing tested, compatible versions of Spring and third-party libraries. Import it so you declare dependencies without versions and get a consistent, curated version set.

open as a page

What is spring-boot-starter-parent and why do Spring Boot projects use it as their Maven parent?

level: juniorimportance: must knowfreq 70%
basics
~20 s

It is a special Maven parent POM you inherit from. It sets sensible defaults for you: dependency versions, a Java version, UTF-8 encoding, and it configures the plugin that builds a runnable Spring Boot jar — so you write far less pom.xml.

open as a page

What is a Spring Boot starter, and what problem does it solve?

level: juniorimportance: must knowfreq 85%
basics
~20 s

A starter is one dependency coordinate that pulls in a curated, version-aligned set of libraries for a feature. Example: spring-boot-starter-web adds Spring MVC, embedded Tomcat, and Jackson together, so you declare one line instead of hand-picking and version-matching many jars.

open as a page

In a Maven project that uses spring-boot-starter-parent, how do you override the version of a dependency that Spring Boot manages for you?

level: juniorimportance: must knowfreq 55%
basics
~10 s

Redefine the version property in your own <properties> block. Spring Boot's parent POM sets properties like jackson-bom.version; declaring the same property in your pom.xml overrides the managed version everywhere it's used.

open as a page

In Maven, how do you use the Spring Boot managed versions without inheriting spring-boot-starter-parent?

level: middleimportance: must knowfreq 65%
basics
~10 s

Import the BOM in <dependencyManagement> with type 'pom' and <scope>import</scope>. That pulls in spring-boot-dependencies' managed versions without making the Boot parent your project's parent.

open as a page

What is @ConfigurationProperties and how does it differ from @Value?

level: juniorimportance: must knowfreq 78%
basics
~10 s

@ConfigurationProperties binds a whole group of external properties (from application.yml/properties/env) onto the fields of a POJO in a type-safe way. @Value injects a single property value into one field using a placeholder expression.

open as a page

What does the `spring.config.import` property do, and what is the effect of the `optional:` prefix?

level: juniorimportance: must knowfreq 55%
basics
~10 s

spring.config.import tells Spring Boot to pull in extra config from another location (a file, config tree, etc.) during startup. optional: means: if that location is missing, don't fail — just skip it.

open as a page

What is the spring-boot-configuration-processor, and what does adding it to your build produce?

level: juniorimportance: must knowfreq 55%
basics
~10 s

It is a compile-time annotation processor. When you add it as a dependency, it scans your @ConfigurationProperties classes during compilation and generates META-INF/spring-configuration-metadata.json, which IDEs read to give auto-completion and docs for your properties.

open as a page

What is a Spring profile and how do you activate one?

level: juniorimportance: must knowfreq 80%
basics
~10 s

A profile is a named group of beans and config that is only active in certain environments (like dev or prod). You turn it on with the property spring.profiles.active, e.g. spring.profiles.active=dev.

open as a page

In Spring Boot, if the same property (say server.port) is set in application.properties AND passed as a command-line argument, which value wins and why?

level: juniorimportance: must knowfreq 70%
basics
~10 s

The command-line argument wins. Spring Boot reads config from many places (property sources). When a key exists in several, the higher-priority source overrides the others, and command-line arguments outrank application.properties.

open as a page

What is ApplicationReadyEvent in Spring Boot and when should you run code on it?

level: juniorimportance: must knowfreq 62%
basics
~20 s

ApplicationReadyEvent fires when the application has fully started — the context is refreshed and all runners have finished — so it is safe to say the app is ready to serve requests. Use it for startup work that needs a fully live app.

open as a page

What are CommandLineRunner and ApplicationRunner in Spring Boot, and when do they run?

level: juniorimportance: must knowfreq 65%
basics
~10 s

They are interfaces with a single run() method. Spring Boot calls every such bean once at startup, after the application context is fully built, so you can run one-off initialization code.

open as a page

What does SpringApplication.run(...) do when a Spring Boot application starts?

level: juniorimportance: must knowfreq 78%
basics
~10 s

SpringApplication.run() bootstraps the app: it creates and configures the Spring ApplicationContext, runs auto-configuration, starts any embedded web server, and returns the running context. It's the one line called from main().

open as a page

What is the difference between CommandLineRunner and ApplicationRunner?

level: middleimportance: must knowfreq 60%
basics
~10 s

Both run once at startup. CommandLineRunner.run receives the raw String[] arguments. ApplicationRunner.run receives an ApplicationArguments object that has already parsed those strings into --option flags and plain (non-option) arguments.

open as a page

How does Spring Boot decide whether an app is SERVLET, REACTIVE, or NONE, and how do you override it?

level: middleimportance: must knowfreq 62%
basics
~20 s

Boot inspects the classpath. If Spring MVC (servlet) classes are present it picks SERVLET; if only WebFlux is present it picks REACTIVE; if no web classes are present it picks NONE. Override with setWebApplicationType() or spring.main.web-application-type.

open as a page

What is the default embedded server in a Spring Boot servlet web application, and how does it get there?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Embedded Apache Tomcat. When you add spring-boot-starter-web, it transitively pulls in spring-boot-starter-tomcat, so Spring Boot auto-configures and starts an embedded Tomcat on port 8080 by default.

open as a page

How do you enable HTTPS/TLS on Spring Boot's embedded web server?

level: juniorimportance: must knowfreq 55%
basics
~10 s

Provide a keystore file and set server.ssl.* properties: server.ssl.key-store (path), server.ssl.key-store-password, server.ssl.key-store-type, and server.ssl.key-alias. Spring Boot configures the embedded server's connector to serve HTTPS on server.port.

open as a page

How do you change the port and base URL path of a Spring Boot app, and what are the defaults?

level: juniorimportance: must knowfreq 78%
basics
~10 s

Set server.port (default 8080) to change the listening port, and server.servlet.context-path (default /) to prefix every URL. Both go in application.properties/application.yml.

open as a page

How do you switch a Spring Boot servlet app from Tomcat to Jetty or Undertow?

level: middleimportance: must knowfreq 60%
basics
~10 s

Exclude spring-boot-starter-tomcat from spring-boot-starter-web, then add spring-boot-starter-jetty (or spring-boot-starter-undertow). Boot's auto-configuration detects the new server on the classpath and uses it instead.

open as a page

Explain `server.tomcat.threads.max` and `server.tomcat.accept-count`. How do they interact under load?

level: middleimportance: must knowfreq 70%
basics
~10 s

threads.max (default 200) is the max worker threads that process requests. accept-count (default 100) is the OS backlog queue of connections waiting when all threads are busy; beyond it, new connections are refused.

open as a page

How do you build a container image from a Spring Boot application without writing a Dockerfile, and what mechanism makes this possible?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Run the built-in goal: ./gradlew bootBuildImage (Gradle) or ./mvnw spring-boot:build-image (Maven). Spring Boot uses Cloud Native Buildpacks to turn your app into an OCI (Docker-compatible) container image, no Dockerfile needed.

open as a page

How do you run a Spring Boot application locally with the Maven or Gradle plugin, and what do those plugins add over a plain build?

level: juniorimportance: must knowfreq 75%
basics
~20 s

With Maven run mvn spring-boot:run; with Gradle run ./gradlew bootRun. Both compile and start your @SpringBootApplication main class in dev. The plugins also build an executable jar containing all dependencies so java -jar just works.

open as a page

What is Spring Boot DevTools and what does it give you during development?

level: juniorimportance: must knowfreq 55%
basics
~20 s

spring-boot-devtools is an optional dev-only dependency. It automatically restarts your app when class files change, refreshes the browser via LiveReload, applies developer-friendly property defaults (like disabling template caching), and is left out of production jars.

open as a page

What is a Spring Boot executable fat jar, and how is it structured internally?

level: juniorimportance: must knowfreq 70%
basics
~10 s

A single runnable jar containing your compiled classes plus all dependency jars. You run it with java -jar app.jar. Spring puts your code in BOOT-INF/classes and dependency jars in BOOT-INF/lib.

open as a page

How do you control the resulting image's name and push it directly to a registry from bootBuildImage / spring-boot:build-image?

level: middleimportance: must knowfreq 65%
basics
~10 s

Set the image name (imageName in Gradle, <image><name> in Maven, or --imageName= / -Dspring-boot.build-image.imageName=). To push, enable publish (publish = true / <publish>true</publish>) and provide registry credentials via docker.publishRegistry.

open as a page