🎯 What you will learn
Spring Boot eliminates boilerplate configuration by auto-detecting JARs on the classpath and wiring beans for you. By the end of this lesson you will be able to:
- Create a Spring Boot 3 project with Maven and the
spring-boot-starter-parent - Understand
@SpringBootApplicationand how auto-configuration works - Write a
@RestControllerwith@GetMappingand return JSON - Configure port and application name via
application.properties - Expose liveness/readiness probes with Spring Boot Actuator
- Run the app with
mvn spring-boot:runand package it as an executable JAR
@SpringBootApplication combines is the most common gap.
🌍 Real-world scenario
Samuel's team at NairaSwift needs to stand up a new micro-service for cross-border NGN payments in one afternoon. Spring Boot's auto-configuration and embedded Tomcat mean they go from blank Maven project to live HTTP endpoint without a single XML servlet config.
🚀 Block 1 — Project setup: pom.xml + application.properties
Start by creating the Maven project skeleton. The spring-boot-starter-parent manages all dependency versions — you never need to specify a version for any Spring starter.
Auto-configuration tip: Adding spring-boot-starter-web to the classpath is all Spring Boot needs to create a DispatcherServlet, embed Tomcat, and configure Jackson for JSON serialisation — zero XML required.
☕ Block 2 — Main class + HelloController
The entry point is a plain Java main() method. @SpringBootApplication combines three annotations: @Configuration, @EnableAutoConfiguration, and @ComponentScan.
🩺 Block 3 — Actuator health endpoint
Spring Boot Actuator adds production-ready endpoints for monitoring. The /actuator/health endpoint is what Kubernetes liveness and readiness probes call to decide whether to route traffic.
Production tip: Never expose all actuator endpoints in production — an attacker with access to /actuator/env or /actuator/heapdump can read secrets. Restrict with management.endpoints.web.exposure.include=health,info and add authentication.
🎤 Interview Q&A
Spring Boot detects JARs on the classpath and automatically creates appropriate beans. For example, seeing spring-boot-starter-web triggers DispatcherServlet, Jackson, and Tomcat setup — no XML required. Auto-configuration classes are listed in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports and each one is guarded by @Conditional* annotations so beans are only created when their prerequisites are present.
@Controller is for MVC views (Thymeleaf, JSP). @RestController = @Controller + @ResponseBody, meaning every method return value is serialised to JSON and sent as the HTTP response body. You don't need to annotate each method individually with @ResponseBody.
@EnableAutoConfiguration reads META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Each listed class is a @Configuration with @Conditional* annotations; a bean is only registered when its condition (e.g., a class present on classpath, a property set) evaluates to true. You can see all conditions evaluated at startup by running with --debug flag.
Set the environment variable SERVER_PORT, pass --server.port=9090 as a command-line argument, or set the JVM system property -Dserver.port=9090. Spring Boot's relaxed binding resolves all three forms. Command-line arguments override environment variables, which override application.properties.
SpringApplication.run() creates the ApplicationContext, triggers auto-configuration, instantiates and wires all beans, then starts the embedded Tomcat (DispatcherServlet is registered). Finally ApplicationReadyEvent fires. Only then does Tomcat accept incoming connections. The whole process is typically under 2 seconds in a lean service.
📝 Quiz — 5 questions
Next: REST Controllers and Routes →
⚠️ Common mistakes
@SpringBootApplication(scanBasePackages = "io.nairaswift").server.port in application.properties or kill the conflicting process with lsof -i :8765.mvn spring-boot:run won't work and the JAR won't be executable. Always include it in the <build> section of your pom.xml.String sends text/plain, not JSON. Wrap in a Map<> or a record/class for proper application/json responses.✅ Key takeaways
- @SpringBootApplication + main() = runnable micro-service
- @RestController + @GetMapping wire HTTP routes in ~5 lines
- application.properties controls port, logging, and feature flags
- Actuator /health and /info are free observability endpoints
- mvn spring-boot:run for dev; mvn package then java -jar for production
From Hello World to production API
Join the Best AI Programs — three 5-month courses, fully online, with placement assistance. Week 1 is free.
Explore our AI-era courses →