10 · Spring and Spring Boot / LESSON 45 OF 102
Generate and run Spring Boot
Spring manages objects; Boot supplies conventions and auto-configuration.
Before this lesson: JdbcTemplate and exception translation
Understand the topic
At start.spring.io choose Maven, Java 21, Jar, package com.example.tasks, and a stable Spring Boot 4.1.x patch. Select Spring Web (MVC), Validation, and Actuator. Generate and unzip. Add JPA and Security only when reaching those lessons.
Keep the application class in the root package so scanning finds its subpackages. @SpringBootApplication combines configuration, scanning, and auto-configuration. Run ./mvnw spring-boot:run; Windows uses .\mvnw.cmd spring-boot:run.
EXAMPLE · JAVA
src/main/java/com/example/tasks/TasksApplication.java
package com.example.tasks;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TasksApplication {
public static void main(String[] args) {
SpringApplication.run(TasksApplication.class, args);
}
}What to expect
The application starts on port 8080. GET / returns 404 until you create a controller.
YOUR TURN
Put it into practice
- 01Inspect generated starter dependencies.
- 02Run the commands from the Maven lesson.
- 03Explain why a controller outside the scanned package is missing.
Pass a quiz or complete a lab to check today’s streak. Each lesson counts once per day, including when you review it later.
UNDER THE HOOD
Build the mental model
Boot makes decisions from the classpath, configuration, and existing beans; it does not replace Java or Spring.
- 01A starter supplies compatible dependencies. Auto-configuration contributes beans only when its conditions match; defining your own bean can cause a default to back off.
- 02Component scanning starts from the application package. Keep feature packages underneath it or explicitly configure scanning deliberately.
- 03Startup errors often describe a missing bean, bad property, or unavailable dependency. Read the deepest relevant cause, not just Application failed to start.
A mistake worth avoiding
Adding every starter at once makes failures harder to isolate.
DEBUGGING ROOM
Something broke. Where do you look?
A controller is compiled but every request returns 404.
Before revealing the diagnosis, write down your first investigation step.
CHECK YOUR UNDERSTANDING
Why might Boot stop supplying a default bean?
BUILD IT YOURSELF
Inspect an application startup
- 1.Generate only Web, Validation, and Actuator initially.
- 2.Start with the wrapper and inspect logs.
- 3.Add one controller and verify its mapping.
Acceptance checklist
Lab completion is your self-report. Knowledge checks do not certify project quality.
RETRIEVE IT FROM MEMORY
What inputs control auto-configuration?
Revisit this lesson in three days after a successful check or lab.
Ready for the next step?
Start the app from a terminal and distinguish Spring from Boot.
Reading is separate from passing a knowledge check or completing a lab.