Spring Boot 4 cheatsheet

Spring Boot 4: Create and run

6 common Spring Boot 4 tasks.

Generate a project

Download a starter project from start.spring.io with the dependencies you choose.

curl https://start.spring.io/starter.zip -d type=maven-project -d language=java -d dependencies=web,data-jpa,actuator -d name=demo -o demo.zip

Run with Maven

Build and start the app with the Maven wrapper.

./mvnw spring-boot:run

Run with Gradle

Build and start the app with the Gradle wrapper.

./gradlew bootRun

Package an executable jar

Build a jar that contains the app and its dependencies.

./mvnw clean package

Run the jar

Start the packaged application.

java -jar target/demo-0.0.1-SNAPSHOT.jar

Build a container image

Build an OCI image with Cloud Native Buildpacks, no Dockerfile needed. Needs Docker running.

./mvnw spring-boot:build-image

Was this page helpful?