Skip to main content

Chapter 1: Spring Initializr

Introduction​

Spring Initializr is a web project generator that allows you to quickly create a Spring Boot project with the necessary dependencies and basic configuration. It is the recommended starting point for any new Spring Boot project.

Chapter Objectives​

By the end of this chapter, you will be able to:

  • Use Spring Initializr to create Spring Boot projects
  • Understand the different configuration options
  • Choose the right dependencies for your project
  • Generate and import a project into your IDE

What is Spring Initializr?​

Definition​

Spring Initializr is a bootstrap tool that generates the basic structure of a Spring Boot project. It:

  • Creates the Maven or Gradle directory structure
  • Generates the pom.xml or build.gradle file with dependencies
  • Adds the main class with @SpringBootApplication
  • Configures the basic resource files

Accessing Spring Initializr​

There are several ways to access Spring Initializr:

  1. Web Interface: https://start.spring.io/
  2. Integrated IDE: IntelliJ IDEA, VS Code with Spring extensions
  3. Spring CLI: Command line
  4. REST API: For automation

Spring Initializr Web Interface​

Access URL​

https://start.spring.io/

Main Sections​

The interface is divided into several sections:


Project Configuration​

1. Project Type​

Available Choices:

TypeDescriptionUsage
MavenXML build toolRecommended for beginners, well-documented
GradleGroovy/Kotlin DSL build toolMore modern, faster, concise syntax

Recommendation: Maven for this course (more standard in the Java industry)

2. Language​

Available Choices:

LanguageDescriptionLevel
JavaMain language of SpringRecommended
KotlinModern language by JetBrainsAdvanced
GroovyDynamic languageLess common

Recommendation: Java (language of this course)

3. Spring Boot Version​

Version format: X.Y.Z

  • X: Major version (major changes)
  • Y: Minor version (new features)
  • Z: Patch version (bug fixes)

Example:

3.2.0

Version types:

TypeSuffixMeaningUsage
ReleaseNoneStable versionProduction
Snapshot-SNAPSHOTDevelopment versionDevelopment only
Milestone-M1, -M2Beta versionTesting
Release Candidate-RC1Release candidateFinal testing

Recommendation: Always choose the latest stable version (no suffix)


Project Metadata​

Metadata Structure​

1. Group​

Definition: Organization or team identifier (Maven convention)

Format: Reversed domain name

Examples:

com.example          # Generic example
com.inskillflow # Organization inskillflow
org.springframework # Spring Framework

Convention: Use your reversed domain or com.example for exercises

2. Artifact​

Definition: Unique project identifier

Format: Lowercase letters, hyphens for spaces

Examples:

greeting-app
user-management-service
e-commerce-backend

Convention: Descriptive name in kebab-case

3. Name​

Definition: Human-readable project name

Format: Human-readable name

Examples:

Greeting Application
User Management Service
E-Commerce Backend

4. Description​

Definition: Short project description

Example:

Spring Boot application to manage greetings

5. Package Name​

Definition: Root Java package of the project

Format: Automatically generated: {group}.\{artifact\}

Example:

com.example.greeting

Resulting structure:

src/main/java/com/example/greeting/
├── GreetingApplication.java
├── controller/
├── service/
└── model/

6. Packaging​

Available Choices:

TypeDescriptionUsage
JARJava Archive (standalone)Spring Boot applications with embedded server
WARWeb ArchiveDeployment on external server (Tomcat, etc.)

Recommendation: JAR (Spring Boot includes its own server)

Difference:

7. Java Version​

Versions supported by Spring Boot 3.x:

VersionSupportRecommendation
Java 17LTSRecommended
Java 21LTSVery recent
Java 11Old LTSNot supported by Spring Boot 3.x

Important Note: Spring Boot 3.x requires minimum Java 17


Dependency Management​

What is a Dependency?​

A dependency is an external library that your project uses.

Spring Boot Starters​

Spring Boot uses the concept of "starters" - bundled dependencies.

Format of a starter:

spring-boot-starter-{technology}

Dependency Categories​

1. Web​

StarterDescriptionUsage
Spring WebREST APIs, Spring MVCREST web applications
Spring Reactive WebWebFlux (reactive)Highly scalable applications

2. SQL (Relational Databases)​

StarterDescription
Spring Data JPAORM with Hibernate
JDBC APILow-level SQL access
MyBatis FrameworkSQL/Java mapping

3. NoSQL​

StarterDescription
Spring Data MongoDBDocument database
Spring Data RedisIn-memory cache
Spring Data ElasticsearchFull-text search

4. Security​

StarterDescription
Spring SecurityAuthentication and authorization
OAuth2 ClientSocial login (Google, Facebook)
OAuth2 Resource ServerProtected API

5. SQL Drivers​

DriverDatabase
PostgreSQL DriverPostgreSQL
MySQL DriverMySQL/MariaDB
H2 DatabaseIn-memory database (tests)
Oracle DriverOracle Database

6. I/O​

StarterDescription
ValidationData validation (@Valid)
Spring Web ServicesSOAP Web Services
Spring for Apache KafkaKafka Messaging

7. Developer Tools​

ToolDescriptionUsage
Spring Boot DevToolsAuto-reloadingDevelopment
LombokReduces boilerplate codeProductivity
Spring Configuration ProcessorConfig autocompletionDevelopment

Dependencies for a Simple REST Project​

For a basic REST application, choose:

✅ Spring Web
✅ Spring Boot DevTools

Dependencies for a Complete Application​

For an application with a database:

✅ Spring Web
✅ Spring Data JPA
✅ PostgreSQL Driver (or other)
✅ Validation
✅ Spring Boot DevTools
✅ Lombok (optional)

Generation and Download​

Generation Options​

Available Buttons:

  1. EXPLORE (Ctrl + Space)

    • Preview project structure
    • View pom.xml content
    • Check generated files
  2. SHARE

    • Generate a shareable link
    • Share configuration with the team
  3. GENERATE (Ctrl + Enter)

    • Download project as ZIP
    • Ready to be unzipped and imported

Structure of the Generated ZIP​

greeting-app.zip
└── greeting/
├── .mvn/ # Maven Wrapper
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/greeting/
│ │ │ └── GreetingApplication.java
│ │ └── resources/
│ │ ├── static/ # Static files (CSS, JS, images)
│ │ ├── templates/ # Templates (Thymeleaf)
│ │ └── application.properties
│ └── test/
│ └── java/
│ └── com/example/greeting/
│ └── GreetingApplicationTests.java
├── .gitignore
├── mvnw # Maven wrapper (Unix)
├── mvnw.cmd # Maven wrapper (Windows)
├── pom.xml # Maven configuration
└── HELP.md

Import into an IDE​

Option 1: Visual Studio Code​

Steps:

  1. Unzip the ZIP
  2. VS Code → File → Open Folder
  3. Select the greeting folder
  4. Wait for automatic Maven import
  5. Required extensions:
    • Extension Pack for Java
    • Spring Boot Extension Pack

Option 2: IntelliJ IDEA​

Steps:

  1. Unzip the ZIP
  2. IntelliJ → File → Open
  3. Select the greeting folder
  4. IntelliJ automatically detects the Maven project
  5. Wait for indexing

Option 3: Eclipse/Spring Tool Suite (STS)​

Steps:

  1. Unzip the ZIP
  2. Eclipse → File → Import
  3. Maven → Existing Maven Projects
  4. Select the greeting folder
  5. Finish

Alternatives to the Web Interface​

1. Spring Initializr in VS Code​

Installation:

  • Extension: Spring Initializr Java Support

Usage:

  1. Ctrl + Shift + P
  2. Type: "Spring Initializr: Create a Maven Project"
  3. Follow the prompts

2. Spring CLI​

Installation:

# macOS
brew install spring-boot

# Linux/Windows
# Download from: https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started.html#getting-started-installing-the-cli

Usage:

spring init \
--dependencies=web,data-jpa,postgresql \
--name=greeting \
--group-id=com.example \
--artifact-id=greeting \
greeting-app

3. Spring Initializr REST API​

Base URL:

https://start.spring.io

Example with curl:

curl https://start.spring.io/starter.zip \
-d dependencies=web,data-jpa \
-d name=greeting \
-d groupId=com.example \
-d artifactId=greeting \
-o greeting.zip

Practical Exercises​

Exercise 1: Create a Simple Project​

Objective: Create a simple REST project

Instructions:

  1. Go to https://start.spring.io/
  2. Configure:
    • Type: Maven
    • Java: 17
    • Group: com.example
    • Artifact: hello-rest
  3. Add: Spring Web
  4. Generate and download
  5. Import into VS Code

Exercise 2: Create a Project with Database​

Objective: Create a project with JPA

Instructions:

  1. Go to https://start.spring.io/
  2. Configure:
    • Type: Maven
    • Java: 17
    • Group: com.example
    • Artifact: user-manager
  3. Add:
    • Spring Web
    • Spring Data JPA
    • PostgreSQL Driver
    • Validation
  4. Generate and explore the pom.xml

Exercise 3: Analyze a pom.xml​

Objective: Understand the generated dependencies

Instructions:

  1. Generate a project with Spring Web
  2. Open the pom.xml
  3. Identify:
    • The Spring Boot parent
    • The web starter
    • The Spring Boot Maven plugin
  4. List all transitive dependencies

Review Questions​

  1. What is Spring Initializr?

  2. What is the difference between Maven and Gradle?

  3. What does "starter" mean in Spring Boot?

  4. What is the convention for the Group ID?

  5. Why choose JAR over WAR for Spring Boot?

  6. What is the minimum Java version for Spring Boot 3.x?

  7. What is Spring Boot DevTools used for?

  8. Which dependency is needed to create REST APIs?


Chapter Summary​

Key Points​

  • Spring Initializr quickly generates Spring Boot projects
  • Accessible via web, IDE, CLI, or API
  • Configuration in 3 sections: Project, Metadata, Dependencies
  • "Starters" group coherent dependencies
  • JAR is the recommended packaging for Spring Boot
  • Java 17+ is required for Spring Boot 3.x

Best Practices​

  • Use stable versions of Spring Boot
  • Choose only necessary dependencies
  • Follow Maven naming conventions
  • Use DevTools in development
  • Version code from creation

Next Steps​

In the next chapter, we will explore in detail:

Chapter 2: Structure of a Spring Boot Project

  • Package organization
  • Role of each file
  • Naming conventions
  • Layered architecture

Back to Module 2