Running a Spring Boot application starts your program so it can listen for requests and do its work.
0
0
Running a Spring Boot application in Spring Boot
Introduction
When you want to test your web app locally on your computer.
When you want to see if your backend service is working.
When you want to run your app to handle real user requests.
When you want to debug or develop new features in your Spring Boot project.
Syntax
Spring Boot
mvn spring-boot:run # or if using Gradle ./gradlew bootRun # Or run the main class directly java -jar target/your-app.jar
You can use Maven or Gradle commands to start the app during development.
After building, you can run the packaged jar file with java -jar.
Examples
This command runs the Spring Boot app using Maven. It compiles and starts the app.
Spring Boot
mvn spring-boot:run
This command runs the Spring Boot app using Gradle. It builds and starts the app.
Spring Boot
./gradlew bootRun
This runs the packaged Spring Boot app jar file directly after building.
Spring Boot
java -jar target/myapp-0.0.1-SNAPSHOT.jarSample Program
This is a minimal Spring Boot application. The @SpringBootApplication annotation sets up the app. The main method starts it.
Spring Boot
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
OutputSuccess
Important Notes
Make sure you have Java installed and your build tool (Maven or Gradle) set up.
The console shows logs when the app starts, including a message that it started successfully.
You can stop the app anytime by pressing Ctrl+C in the terminal.
Summary
Running a Spring Boot app means starting it so it can do its work.
You can run it using Maven, Gradle, or by running the jar file.
The main method with SpringApplication.run() is the entry point.