C
Spring Boot/Setup/Lesson 02

Your First Spring Boot Project — From start.spring.io to Running

30 min·theory

Your First Spring Boot Project — From start.spring.io to Running

🎯 What You'll Be Able to Do After This Lesson

After finishing this lesson, you'll be able to confidently do the following three things.

  • ✅ Create and run a project in under 5 minutes using start.spring.io
  • ✅ Split application.yml into multi-profile configurations (dev/prod)
  • ✅ Explain the 3 things @SpringBootApplication does under the hood

Keep these goals as a checklist — close the lesson once you can answer all of them.

Creating a Project with start.spring.io

The Official Generator for Spring Boot

https://start.spring.io is the official project generator provided by the Spring team. Pick your dependencies with a click and download a zip.

Initial Project Settings

Fill in the left-hand form on the page like this:

  • Project: Gradle - Kotlin (Maven works too, but Gradle is recommended for new projects)
  • Language: Java
  • Spring Boot: 3.2.x (LTS line, as of 2026)
  • Group: com.example
  • Artifact: demo (= the project folder name)
  • Name: demo
  • Description: "My first Spring app"
  • Package name: com.example.demo
  • Packaging: Jar (war is for legacy Tomcat deployments)
  • Java: 17 (minimum requirement for Spring Boot 3)

Choosing Dependencies — 5 for Learning

Click ADD DEPENDENCIES and search to add:

1. Spring Web — build REST APIs
2. Spring Boot DevToolsauto-restarts on code changes
3. Lombok — eliminates @Getter/@Setter boilerplate
4. H2 Databasein-memory DB (very convenient for learning)
5. Spring Data JPA — automates database operations

Generate → Download → Open

Click GENERATE → download demo.zipunzip it → in IntelliJ, select the folder via Open.

IntelliJ will automatically download Gradle dependencies (takes 1–3 minutes the first time). When the progress bar in the bottom-right stops, you're ready.

Running the App

Open src/main/java/com/example/demo/DemoApplication.java in the project tree:

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

Click the green ▶ on the left or press Shift + F10. If you see the Spring Boot banner and Tomcat started on port 8080 in the console, you're good to go.

Visit http://localhost:8080 in your browser → you'll get a 404 page (normal — no routes defined yet).

Congratulations — a real web server is now running.

application.yml vs application.properties

Both Are the Same Config File

You only need one of the two inside src/main/resources/.

properties — key=value format

properties
server.port=8080
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.jpa.show-sql=true
logging.level.org.springframework=INFO

yml — hierarchical indentation

yaml
server:
  port: 8080
spring:
  datasource:
    url: jdbc:h2:mem:testdb
    username: sa
  jpa:
    show-sql: true
logging:
  level:
    org.springframework: INFO

Which One to Use

Almost all new projects use application.yml — the hierarchical structure makes it far more readable.

properties remains in older projects and simple configurations.

5 Commonly Used Settings

yaml
server:
  port: 8080                 # change the default port
  servlet:
    context-path: /api       # prefix /api on all URLs

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: root
    password: ${DB_PASSWORD}  # reference an environment variable

  jpa:
    hibernate:
      ddl-auto: update        # auto-create tables (not for production)
    show-sql: true            # print SQL to the console

logging:
  level:
    org.springframework.web: DEBUG

Environment-Specific Separation — application-{profile}.yml

code
resources/
├── application.yml           # shared
├── application-dev.yml       # development
└── application-prod.yml      # production

At startup, select a profile with --spring.profiles.active=prod or the environment variable SPRING_PROFILES_ACTIVE=prod. The standard pattern for keeping production passwords out of git.

@SpringBootApplication — What That Single Annotation Really Is

An Annotation That Combines 3 in One

@SpringBootApplication is actually a meta-annotation that bundles three annotations together:

java
@SpringBootConfiguration      // = @Configuration
@EnableAutoConfiguration       // the heart of Spring Boot magic
@ComponentScan                 // scans this package and its sub-packages
public @interface SpringBootApplication { }

What Each Annotation Does

1. @Configuration

Tells Spring this class is a Bean configuration class. Allows you to declare @Bean methods inside it.

2. @EnableAutoConfiguration

Spring Boot magic. Looks at the libraries on the classpath and automatically configures them.

  • Detects spring-boot-starter-web → auto-configures Tomcat + Spring MVC
  • Detects H2 Database → auto-connects an in-memory DB
  • Detects Spring Data JPA → auto-configures the JPA EntityManager

The core feature that replaced 100 lines of XML config with zero. Without this, you'd be back in the old Spring era of configuration hell.

3. @ComponentScan

Scans from the package where this class lives down through all sub-packages, and registers every @Component/@Service/@Repository/@Controller as a Bean.

That is why the location of DemoApplication matters — all your code must be under the DemoApplication package to be picked up automatically.

Your First Controller — Hello, World!

Add HelloController.java to the same package:

java
package com.example.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

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

After restarting the server (automatic if DevTools is present), visit http://localhost:8080/helloHello, Spring Boot!

This is the moment you rendered your first server-side page.

Summary

A single @SpringBootApplication line activates dozens of auto-configurations. If an interviewer asks 'What does @SpringBootApplication do?', you should be able to answer with the 3 points above.

🤖 Try Asking AI Like This

Once you understand the concepts in this lesson, you can give AI specific instructions — not vague 'fix this' requests, but vocabulary-driven prompts. That is where token savings begin.

  • "Create a project skeleton using Spring Boot 3.2 + Java 17 + Gradle + H2"
  • "Add multi-profile separation (dev/prod) to application.yml"
  • "Configure this project to start on port 9000 instead of 8080"

Why This Saves Tokens

Without the right concepts, you have to ask "What does that mean?" after every AI response. Those follow-up questions eat tokens. Master the concepts once, and the conversation wraps up in a single exchange.

Your First Spring Boot Project — From start.spring.io to Running - Spring Boot