Creating a Simple Spring Boot Application
Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).
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
mainmethod 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:runin the terminal.Access the application at
http://localhost:8080.