Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 2

    Spring Boot Introduction

    Spring Boot is an opinionated layer on the Spring Framework.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Spring Boot is an opinionated layer on the Spring Framework. It auto-configures beans from the classpath, groups dependencies into starters, embeds Tomcat (or Jetty/Undertow), and packages a fat JAR you start with java -jar.

    Classic Spring often needed XML or Java config for a DispatcherServlet, a view resolver, and a data source before a single endpoint worked. Boot collapses that ceremony: put spring-boot-starter-web on the classpath, annotate one class with @SpringBootApplication, and you have a listening HTTP server.

    Auto-configuration is conditional. Classes under org.springframework.boot.autoconfigure register beans only when markers are present (for example, a DataSource type and a JDBC driver). You override by defining your own @Bean of the same type or by excluding a specific auto-configuration.

    For TechLearningPRO Orders, Boot is the reason a new engineer can clone the repo, run the Maven wrapper, and hit /api/orders/{id} without installing an application server.

    Purpose of this lesson

    Explain starters, auto-configuration, and the embedded server well enough to predict what Boot will wire when Orders adds starter-web — and what still remains your job.

    Understanding the topic

    Boot removes boilerplate; it does not remove design.

    • Starters: version-aligned dependency sets (spring-boot-starter-web, -data-jpa, -validation, -actuator).
    • Auto-configuration: classpath-driven @Bean registration with @ConditionalOn* guards.
    • Embedded server: the process is the server; production usually runs the fat JAR (or a container wrapping it).
    • Actuator: health and metrics endpoints — expose them carefully, never wide-open on the public internet.
    • Your job: domain rules, boundaries, security, and explicit configuration for anything environment-specific.

    Step-by-step explanation

    1. Add only the starters Orders needs for the current lesson.
    2. Run the app and read the auto-configuration report when something unexpected appears (--debug or the condition evaluation report).
    3. Prefer replacing a Boot bean with your own @Bean over copying auto-config classes.
    4. Treat Actuator as a production feature with auth and network policy — not a free debug UI.

    Informative example

    Smallest Boot web app. Expected JSON when you GET /hello after ./mvnw spring-boot:run:

    java
    import java.util.Map;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    @SpringBootApplication
    @RestController
    public class App {
    public static void main(String[] args) {
    SpringApplication.run(App.class, args);
    }
    @GetMapping("/hello")
    Map<String, String> hello() {
    return Map.of("message", "Hello, Orders");
    }
    }

    Output

    {"message":"Hello, Orders"}

    Real-world use

    Platform teams standardize on Boot so every microservice shares the same way to open a port, bind config, and expose health. Orders joins that convention: one parent BOM, one actuator story, one packaging story — which cuts onboarding time when a new hire lands on checkout.

    Security implications

    A minimal Boot app is often wide open until you add Spring Security.

    • Do not deploy the twelve-line hello app as a public service.
    • Actuator can leak env and config; lock it down before production.
    • Dependencies in starters expand the CVE surface — track them in CI.

    Best practices

    • Let the Boot BOM manage versions; avoid random overrides without a reason.
    • Use --debug once when learning why a DataSource did or did not appear.
    • Keep business logic out of the @SpringBootApplication class as soon as the skeleton grows.

    Common mistakes

    • Assuming auto-configuration 'just knows' your intent — missing drivers mean missing beans, not magic.
    • Copying Boot 2 security or JPA packages into a Boot 3 build.
    • Enabling every Actuator endpoint on the same port as the public API.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionWhat is a Spring Boot starter?+

    Answer

    A curated dependency descriptor that pulls a compatible set of libraries (and often triggers related auto-configuration) so teams do not hand-align versions.
    2IntermediateQuestionHow do you override an auto-configured bean?+

    Answer

    Define your own @Bean of that type (Boot backs off when you take ownership), or exclude the specific auto-configuration class if you must disable a whole slice.
    3IntermediateQuestionWhy prefer an executable JAR over a WAR on an external Tomcat for new services?+

    Answer

    The process is self-contained, CI produces one artifact, and local java -jar matches production more closely. WARs remain for legacy app-server estates.

    Hands-on exercise

    Lab. Create the hello app above, run it, curl /hello, then add spring-boot-starter-actuator and list which endpoints appear. Do not expose them publicly.

    Summary

    Spring Boot shortens the path from empty repo to listening port. Orders uses that path so later lessons can focus on rules, data, and security instead of server ceremony.

    Ready to mark this lesson complete?Track your journey across the entire course.