Spring Boot Tutorial
Spring Boot - Software Setup and Configuration (STS/Eclipse/IntelliJ)
Prerequisite (Spring Core Concepts)
Spring Boot Core
Spring Boot with REST API
Spring Boot with Database and Data JPA
Spring Boot with Kafka
Spring Boot with AOP
Running a Spring Boot application is straightforward, and there are multiple ways to do so. Here's how you can run your Spring Boot application:
If you used Spring Initializr to bootstrap your project with Maven, it would include the Spring Boot Maven plugin by default. Navigate to the root directory of your project using a terminal or command prompt and execute:
mvn spring-boot:run
This will start your Spring Boot application.
If your project uses Gradle, you can run:
./gradlew bootRun
(For Linux or macOS)
Or:
gradlew bootRun
(For Windows)
You can also package your application as a JAR or WAR and then run it. To package it as a JAR:
For Maven:
mvn clean package
For Gradle:
./gradlew build
Once packaged, navigate to the target
directory (for Maven) or build/libs
directory (for Gradle), and you'll find your JAR. You can run it using:
java -jar your-artifact-name.jar
Most modern IDEs (Integrated Development Environments) like IntelliJ IDEA, Eclipse, or STS (Spring Tool Suite) provide support for Spring Boot applications.
In IntelliJ IDEA: Navigate to the main class (the one annotated with @SpringBootApplication
) and click on the green arrow (Run) next to the class declaration.
In Eclipse or STS: Right-click on the main class and choose 'Run As' -> 'Java Application'.
Started YourApplicationName in X seconds
. This indicates your application has started successfully.Remember to navigate to the appropriate URL in your web browser (typically http://localhost:8080
) to interact with your application, unless you've configured a different port.
Launching a Spring Boot application from the command line:
./mvnw spring-boot:run
./gradlew bootRun
Using Maven or Gradle to build and run a Spring Boot application:
mvn clean install java -jar target/your-application.jar
./gradlew build java -jar build/libs/your-application.jar
Debugging a Spring Boot application in an IDE or command line:
java -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 your-application.jar
Running a Spring Boot application in a Docker container:
FROM openjdk:11 COPY target/your-application.jar /app.jar CMD ["java", "-jar", "/app.jar"]