Spring Framework Tutorial
Creating a Project with Spring Initializr
Spring Initializr, at start.spring.io, generates a ready-to-run Spring Boot project: a correct pom.xml or build.gradle, the Maven or Gradle wrapper, an application class, a test class and the standard folder structure. Professional teams use it constantly because it guarantees compatible dependency versions.
You can use Initializr from the website, from your IDE (IntelliJ, Eclipse, and VS Code all have it built in), and from the command line with curl. This lesson covers each option and explains every field.
Using the website
Open start.spring.io and fill in the form. The choices are explained below, using the options that the current Initializr offers.
- Project - Maven, Gradle with Groovy, or Gradle with Kotlin.
- Language - Java, Kotlin or Groovy. This course uses Java.
- Spring Boot - pick the release version (4.1.1 at the time of writing). Avoid SNAPSHOT and milestone (M) versions for real work.
- Group and Artifact - group is your reverse domain such as com.webnest; artifact is the project name such as hello. Together they define the base package.
- Packaging - Jar for normal applications (embedded server), War only if you must deploy to an external servlet container.
- Java - 17, 21, 25 or a newer release, and it must not be higher than your installed JDK.
- Dependencies - click Add Dependencies and search. Choose Spring Web for REST and MVC, Spring Data JPA for databases, Validation, Spring Security, Thymeleaf, Actuator, and so on.
Commonly used dependency names
The identifiers below are the ones Initializr uses. You can pass them to the command-line form as a comma-separated list.
web- Spring Web (MVC and REST, embedded Tomcat).data-jpa- Spring Data JPA with Hibernate.validation- Bean Validation (Jakarta Validation).security- Spring Security.thymeleaf- server-side HTML templates.actuator- health and metrics endpoints.devtools- automatic restart during development.h2,postgresql,mysql- database drivers.mail,cache,websocket,kafka,rabbitmq- integration features.
Generating from the command line
Initializr is a web service, so you can call it with curl and unzip the result. This is useful in scripts and when you have no browser. The generated zip contains the whole project.
Generating from your IDE
IntelliJ IDEA (Ultimate) has New Project, Spring Boot (Spring Initializr). Eclipse with Spring Tools has File, New, Spring Starter Project. VS Code has the command "Spring Initializr: Create a Maven Project" from the Spring Boot extension pack. All three call the same service and show the same options.
What you get
Unzip and open the folder in your IDE. You will find the wrapper scripts and .mvn folder, pom.xml, HELP.md with reference links, .gitignore and .gitattributes, an application class in src/main/java, an application.properties file plus empty static and templates folders in src/main/resources, and a test class in src/test/java. The generated application class and test look like the example below.
Examples
Generate a Spring Boot 4.1.1 project with curl (this exact request was tested)
curl "https://start.spring.io/starter.zip?type=maven-project&language=java&bootVersion=4.1.1&javaVersion=17&groupId=com.webnest&artifactId=hello&name=hello&packageName=com.webnest.hello&dependencies=web,actuator,devtools" -o hello.zip
unzip hello.zip -d hello
cd hello
ls
HELP.md
mvnw
mvnw.cmd
pom.xml
src
The generated application class and test (Spring Boot 4.1)
package com.webnest.hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloApplication {
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
}
// src/test/java/com/webnest/hello/HelloApplicationTests.java
@SpringBootTest
class HelloApplicationTests {
@Test
void contextLoads() {
}
}
Common Mistakes
- Choosing a Java version in Initializr that is newer than the JDK installed on your machine.
- Picking a SNAPSHOT or milestone Spring Boot version for a project you intend to keep.
- Adding many dependencies "for later". Every starter adds auto-configuration and startup time; add them when you need them.
- Adding Spring Data JPA without a database driver or datasource. The application then fails at startup because it cannot configure a DataSource.
- Forgetting to unzip the file and trying to open the zip in the IDE.
Key Points to Remember
- start.spring.io generates a compatible, runnable project in seconds.
- You choose build tool, language, Boot version, packaging, Java version and dependencies.
- The same service is available from the website, IDEs and curl.
- The result includes the wrapper, pom.xml or build.gradle, an application class, properties and a test.
Practice the examples
Change an input, predict the result, then compare it with the output. Explain why the result changes.
Use your local JDK or project IDE for these examples. Codelab currently runs Python and HTML/CSS/JavaScript; framework examples may need project dependencies.