Creating a Simple Spring Boot Application
Step-by-step Guide to Creating Your First Spring Boot Application:
Initialize a Spring Boot Project:
Use Spring Initializr to generate a new project.
Select project type (Maven/Gradle), language (Java), and Spring Boot version.
Add dependencies: Spring Web.
Import the Project into Your IDE:
Open the project in your chosen IDE.
Familiarize yourself with the project structure.
Create a Main Application Class:
- This class will contain the
main
method annotated with@SpringBootApplication
.
- This class will contain the
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);
}
}
Run the Application:
Use your IDE to run the application or execute
mvn spring-boot:run
in the terminal.Access the application at
http://localhost:8080
.