Enter Keyword Hear for Search This Blog

Showing posts with label how to create a simple Spring Boot program with step by step. Show all posts
Showing posts with label how to create a simple Spring Boot program with step by step. Show all posts

Friday, 26 September 2025

how to create a simple Spring Boot program with step by step

 

Let’s walk through how to create a simple Spring Boot program — step by step. We’ll build a small “Hello World” REST API using Spring Boot.


🧰 Prerequisites

Make sure you have:

  • Java 17+ installed (java -version)

  • Maven or Gradle

  • Spring Boot (via Spring Initializr)

  • An IDE (like IntelliJ IDEA, Eclipse, or VS Code)


🊄 Step 1: Create a New Project

Option 1 — Use Spring Initializr (recommended)

Go to 👉 https://start.spring.io

Select:

  • Project: Maven

  • Language: Java

  • Spring Boot Version: Latest stable (e.g. 3.3.x)

  • Group: com.example

  • Artifact: demo

  • Dependencies:

    • Spring Web

Click Generate, and it will download a .zip file.
Extract and open it in your IDE.


ðŸ§ą Step 2: Check Project Structure

Your project should look like:

demo/
 ├── src/
 │   ├── main/
 │   │   ├── java/com/example/demo/DemoApplication.java
 │   │   └── resources/application.properties
 │   └── test/
 ├── pom.xml

🧑‍ðŸ’ŧ Step 3: Write a Simple REST Controller

Create a new file:
📄 src/main/java/com/example/demo/HelloController.java

package com.example.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String sayHello() {
        return "Hello, Spring Boot!";
    }
}

This creates a REST endpoint at /hello.


🚀 Step 4: Run the Application

In your IDE, run DemoApplication.java, or in the terminal:

mvn spring-boot:run

You’ll see:

Tomcat started on port 8080

Now open your browser and go to:

👉 http://localhost:8080/hello

You should see:

Hello, Spring Boot!

🎉 You’ve just built your first Spring Boot app!


⚙️ Step 5: Optional — Customize Port

In src/main/resources/application.properties:

server.port=9090

Now your app runs on http://localhost:9090/hello.


🧊 Step 6: Build JAR (optional)

To package it:

mvn clean package

Run it:

java -jar target/demo-0.0.1-SNAPSHOT.jar

Would you like me to show you how to connect this app to a database (like MySQL) or create CRUD APIs next?

Featured post

what is ajax?how to create ajax with php code

Ajax Introduction -  āŠāŠœેāŠ•્āŠļ āŠĻો āŠ‰āŠŠીāŠŊોāŠ— āŠ•āŠ°ી āŠĻે āŠĪāŠŪે āŠŠેāŠœ āŠēોāŠĄ āŠ•ાāŠ°્āŠŊ āŠĩિāŠĻા āŠŽāŠ§ી āŠŪાāŠđિāŠĪી āŠŪેāŠģāŠĩી āŠķāŠ•ો.āŠāŠœેāŠ•્āŠļ āŠĨી āŠĪāŠŪે āŠ•ોāŠˆ āŠŠāŠĢ āŠĄેāŠŸા āŠāŠĄāŠŠ āŠĨી āŠŪેāŠģāŠĩી āŠķāŠ•ો āŠ›ો...