Boot starters and auto-configuration
What you will learn
Spring Boot starts a Spring application with conventions for dependencies, configuration and runtime assembly. A starter supplies dependencies; auto-configuration contributes beans only when its conditions match. Neither guarantees that every application has a server.
- Distinguish a starter, BOM and auto-configuration.
- Explain how Boot chooses an application context and starts it.
- Use a bounded local startup plan and identify a condition that can change the result.
Plain Java examples: save as Main.java in a fresh directory, then run javac --release 21 Main.java and java Main. Boot examples require the separate pinned companion Maven project. Their predicted results are not execution evidence.
Choose a default only if absent
import java.util.function.Supplier;public class Main { static String choose(String user, Supplier<String> fallback) { return user != null ? user : fallback.get(); } public static void main(String[] args) { System.out.println(choose(null, () -> "default")); System.out.println(choose("custom", () -> { throw new AssertionError(); })); }}Expected output:
defaultcustomThe fallback is not evaluated when an explicit value exists. This models one condition; it does not run Spring or prove a bean condition.
Dependency layers
A starter is a curated dependency entry point. The Boot parent imports dependency management and supplies build defaults; a BOM manages versions but does not add libraries. Boot 4.0.10 documents Java 17–27, Framework 7.0.11 or later, Maven 3.6.3+, Gradle 8.14+ in 8.x or 9.x, and Servlet 6.1 (Tomcat 11 or Jetty 12.1). Its managed coordinates list Framework 7.0.11 and Jackson 3.1.8; Jackson 3 is the default JSON family, with Jackson 2 compatibility deprecated. Do not mix the V37 standalone Spring version into the Boot project. Use the BOM rather than guessing transitive versions. Confirm resolved dependencies locally before upgrading.
Conditional startup
@SpringBootApplication combines Boot configuration, auto-configuration and component scanning. Put it at the root of the application package. SpringApplication.run creates and refreshes the context. Conditions examine factors such as available classes, properties and existing beans. A conditional default can back off when a user bean is present; not all configuration does so. --debug logs a conditions report; inspect only this synthetic project. A web starter supplies an embedded server path, whereas a non-web context can run without listening on a socket.
Packaging and boundaries
Use the Boot Maven plugin with its parent to repackage the application jar; java -jar starts the Boot launcher with nested dependencies. Maven resolves dependencies at build time; a local application need not contact Maven Central on every request. Bind to loopback and use the explicit flags in the companion lab. ApplicationRunner executes after context refresh; its success does not establish HTTP readiness or correct external dependencies.
Model an application startup decision
public class Main { static String mode(boolean mvcPresent, boolean nonWeb) { return mvcPresent && !nonWeb ? "web" : "non-web"; } public static void main(String[] args) { System.out.println(mode(true, false)); System.out.println(mode(true, true)); System.out.println(mode(false, false)); }}Expected output:
webnon-webnon-webThe boolean model intentionally omits real classpath detection, reactive applications and custom application context factories.
Boot application entry point
Source-reviewed, NOT RUN. File lab-fixtures/boot-v38/src/main/java/example/bootlab/BootLab.java; use the companion lab README.
package example.bootlab;
import org.springframework.boot.ApplicationRunner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.context.properties.EnableConfigurationProperties;import org.springframework.context.annotation.Bean;import org.slf4j.LoggerFactory;
@SpringBootApplication@EnableConfigurationProperties(LabSettings.class)public class BootLab { public static void main(String[] args) { SpringApplication.run(BootLab.class, args); }
@Bean ApplicationRunner report(LabSettings settings) { return args -> LoggerFactory.getLogger(BootLab.class) .info("LAB batch size: {}", settings.batchSize()); }}Predicted behavior: Application startup and a log containing LAB batch size: 10, with the supplied resources and dependencies.
The runner receives typed settings through a bean method. The context owns the server. Use the lab POM and the next lesson’s settings class.
Pinned Maven project
Source-reviewed, NOT RUN. File lab-fixtures/boot-v38/pom.xml; use the companion lab README.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>4.0.10</version> <relativePath/> </parent> <groupId>example</groupId> <artifactId>boot-lab</artifactId> <version>1.0.0</version> <properties> java.version>21 /java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webmvc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>Predicted behavior: An executable target/boot-lab-1.0.0.jar after a successful Maven package.
The parent manages dependency versions; the plugin repackages the jar. No Maven build was performed.
Common mistakes
Do not treat starter installation as a running service, force every bean into auto-configuration, override managed dependencies independently, or enable debug logging in a real environment without review.
Practice
Implement select(boolean enabled, String supplied) that returns disabled if the feature is off, supplied if present, or default otherwise. Print the results for false/custom, true/custom, and true/null. Explain which decision is application policy rather than Boot behavior.
Expected output:
disabledcustomdefaultCompare with the manual review criteria.
Official reading: Requirements · Dependencies · Build · Auto · JSON. Boot execution and independent review remain pending.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Boot starters and auto-configuration — knowledge check
Spring Boot configuration and operational reasoning.
What does a BOM primarily control?
What is a starter?
When can a conditional default back off?
What does --debug help inspect?
Which artifact is intended to run with java -jar?