Introduction to Spring Boot

🌿 Spring BootLesson 1Beginner

Spring Boot is an opinionated, convention-over-configuration framework built on top of the Spring Framework. It eliminates boilerplate configuration and lets you build production-ready Java applications in minutes, not days.

1 Why Spring Boot?
  • Auto-configuration: Spring Boot auto-configures beans based on the JARs present on your classpath. No XML required.
  • Embedded Server: Ships with embedded Tomcat, Jetty, or Undertow — just run java -jar app.jar.
  • Starter POMs: Curated dependency sets (spring-boot-starter-web, spring-boot-starter-data-jpa, etc.) that eliminate version conflicts.
  • Actuator: Built-in production monitoring endpoints (/health, /metrics, /info).
  • Spring Ecosystem: Seamlessly integrates with Spring Security, Spring Data, Spring Cloud, and more.
2 Your First Spring Boot Application
Java — Main Application Class
package com.example.demo;

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  // Combines @Configuration + @EnableAutoConfiguration + @ComponentScan
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
        // Starts embedded Tomcat on port 8080
    }

    @GetMapping("/")
    public String hello() {
        return "Hello, Spring Boot!";
    }
}
3 Spring Boot vs Plain Spring
FeaturePlain SpringSpring Boot
ConfigurationXML or Java @ConfigurationAuto-configured, minimal setup
Web ServerExternal (deploy WAR)Embedded (run JAR)
DependenciesManual, version-managedStarters with BOM
Startup TimeSlow (heavy XML)Fast (lazy init option)
Production ReadyManual setupActuator built-in
4 Code Challenge
Challenge: Create a Spring Boot app with two endpoints: GET /ping that returns {"status":"ok","timestamp":"..."} and GET /version that returns the app version from application.properties.