Running a Spring Boot Application
Spring Boot provides multiple ways to run an application, making it suitable for development, testing, and production environments. You can run a Spring Boot app directly from an IDE, using build tools like Maven or Gradle, or as an executable JAR file.
1. Run from IDE (IntelliJ / Eclipse / STS)
This is the most common approach during development.
Steps:
- Open the main class annotated with
@SpringBootApplication - Right-click → Run
- Spring Boot automatically:
- Starts the embedded server (Tomcat by default)
- Loads configuration
- Initializes the application
Why use this?
- Fast feedback during development
- Easy debugging and log visibility
- No command-line setup required
2. Run Using Maven
You can run the application using Maven from the terminal:
mvn spring-boot:runWhat happens internally:
- Maven compiles the source code
- Resolves and downloads dependencies
- Executes the Spring Boot main class
Best suited for:
- Local development
- CI/CD pipelines
- Maven-based projects
3. Run Using Gradle
For Gradle-based projects, use:
gradle bootRun
or (recommended):
./gradlew bootRun
Best suited for:
- Gradle projects
- Automated build and deployment setups
4. Run as an Executable JAR (Production-Style)
This is the most common production approach.
Step 1: Build the JAR
mvn clean package
Step 2: Run the JAR
java -jar myapp.jar
Why this is important:
- No external application server required
- Ideal for Docker, Kubernetes, and cloud platforms
- Fully self-contained application
5. Run with a Specific Profile
Spring profiles allow environment-specific configuration.
java -jar myapp.jar --spring.profiles.active=dev
Common use cases:
- Different databases for dev/test/prod
- Different logging levels
- Secure production settings
Spring Boot Application – Run Flow
Developer Action
│
▼
Choose Run Method
│
├── Run from IDE
│ │
│ └── @SpringBootApplication
│ ↓
│ Embedded Server Starts
│ ↓
│ Application Running
│
├── Maven (mvn spring-boot:run)
│ │
│ └── Compile + Dependencies
│ ↓
│ Spring Boot Startup
│ ↓
│ Application Running
│
├── Gradle (bootRun)
│ │
│ └── Gradle Build Lifecycle
│ ↓
│ Spring Boot Startup
│ ↓
│ Application Running
│
└── Executable JAR (java -jar)
│
└── JVM Starts
↓
Embedded Server
↓
Application Running
Conclusion
Spring Boot makes application execution simple, flexible, and production-ready.
Whether you run it from an IDE for development, use Maven or Gradle for automation, or deploy it as an executable JAR in production, Spring Boot handles everything with minimal configuration. Profile support ensures clean separation between environments, making Spring Boot ideal for modern and scalable applications.
