What Is Spring Boot?

Spring Boot is an opinionated extension of the Spring Framework that eliminates boilerplate configuration. Where traditional Spring required extensive XML or Java config, Spring Boot uses convention-over-configuration to get you up and running in minutes. It's the most widely used Java framework for building web applications and microservices.

Creating a New Spring Boot Project

The easiest way to start is with Spring Initializr:

  1. Go to start.spring.io
  2. Choose Maven as the build tool and Java as the language
  3. Select the latest stable Spring Boot version
  4. Add the Spring Web dependency
  5. Click Generate and extract the downloaded ZIP

Open the project in IntelliJ IDEA or VS Code. You'll see the main application class:

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

The @SpringBootApplication annotation enables auto-configuration, component scanning, and configuration properties all at once.

Creating Your First REST Controller

Add a new file called HelloController.java in the same package:

@RestController
@RequestMapping("/api")
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello from Spring Boot!";
    }

    @GetMapping("/greet/{name}")
    public String greet(@PathVariable String name) {
        return "Hello, " + name + "!";
    }
}

Key annotations explained:

  • @RestController — Combines @Controller and @ResponseBody; methods return data directly (not views).
  • @RequestMapping("/api") — Sets the base URL for all routes in this controller.
  • @GetMapping — Maps HTTP GET requests to the method.
  • @PathVariable — Binds a URL segment to a method parameter.

Running the Application

Run the main class from your IDE, or from the terminal:

./mvnw spring-boot:run

Spring Boot starts an embedded Tomcat server on port 8080. Visit http://localhost:8080/api/hello in your browser — you should see the response immediately.

Returning JSON with a Model Class

Real APIs return structured data, not plain strings. Create a simple model:

public class Product {
    private Long id;
    private String name;
    private double price;

    // Constructor, getters, setters
}

Then return it from a controller method:

@GetMapping("/product")
public Product getProduct() {
    return new Product(1L, "Java Book", 29.99);
}

Spring Boot automatically serializes this to JSON: {"id":1,"name":"Java Book","price":29.99}

Common Spring Boot Annotations at a Glance

AnnotationPurpose
@SpringBootApplicationBootstraps the application
@RestControllerMarks class as REST API controller
@GetMapping / @PostMappingMaps HTTP methods to handler methods
@PathVariableBinds URL path segment to parameter
@RequestBodyDeserializes JSON request body to object
@ServiceMarks a business logic class
@RepositoryMarks a data access class
@AutowiredInjects a Spring-managed bean

Next Steps

Once you're comfortable with the basics, explore:

  • Spring Data JPA — Database access with zero boilerplate SQL
  • Spring Security — Authentication and authorization
  • Spring Boot Actuator — Production health and metrics endpoints
  • application.properties — Externalizing configuration

Spring Boot's power lies in how much it handles for you. Focus on writing your business logic — let the framework take care of the infrastructure.