Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Creating a project

Nobody writes a Spring Boot project from scratch. Its skeleton comes from the official generator, Spring Initializr, at start.spring.io. You pick the version, the language and the modules you need, and the generator gives you an archive with a ready project.

What to choose on start.spring.io

FieldValue for the blog
ProjectMaven
LanguageJava
Spring Boot4.1.1 (the latest stable one, without SNAPSHOT or M)
Groupcom.example
Artifactblog
Package namecom.example.blog
PackagingJar
Java25

In the Dependencies section click Add dependencies and add Spring Web. We will add the other modules later, one at a time. The Generate button downloads blog.zip — unpack it and open the folder in IntelliJ IDEA, VS Code or another editor.

The same from a terminal

The generator has a download address, so you can create the project with one command:

curl -o blog.zip "https://start.spring.io/starter.zip?type=maven-project&language=java&bootVersion=4.1.1&groupId=com.example&artifactId=blog&packageName=com.example.blog&javaVersion=25&dependencies=web"

You get the same archive as from the website. Unpack it with tar -xf blog.zip (Windows 10+, macOS, Linux).

What is inside

blog/
├── .mvn/wrapper/maven-wrapper.properties
├── mvnw
├── mvnw.cmd
├── pom.xml
├── HELP.md
└── src/
    ├── main/
    │   ├── java/com/example/blog/BlogApplication.java
    │   └── resources/application.properties
    └── test/
        └── java/com/example/blog/BlogApplicationTests.java
FileWhat it is for
pom.xmlThe project description for Maven: Spring Boot version, dependencies, plugins
mvnw, mvnw.cmd, .mvn/Maven Wrapper: downloads the right Maven version itself, no need to install Maven
BlogApplication.javaThe entry point — a class with a main method
application.propertiesApplication settings
BlogApplicationTests.javaThe first test: checks that the application starts
HELP.mdLinks to documentation for the chosen modules

The main class

// src/main/java/com/example/blog/BlogApplication.java
package com.example.blog;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
 
@SpringBootApplication
public class BlogApplication {
 
    public static void main(String[] args) {
        SpringApplication.run(BlogApplication.class, args);
    }
}

The @SpringBootApplication annotation switches on auto-configuration and the search for your classes in the com.example.blog package and its subpackages. SpringApplication.run starts Spring and the embedded web server.

The settings file

The generator puts one line into application.properties:

# src/main/resources/application.properties
spring.application.name=blog

This is the application name — it appears on every log line. We will add other settings as we need them.

Common mistake

The Spring Boot field may default to a version marked SNAPSHOT or M2 — these are development builds, they change and may not download from Maven Central. Choose a version without such marks. If the project already exists, check the version in pom.xml inside the <parent> block.

Thanks for reading!

Donate to the site — we work hard for you.