?? Day 8: My Spring Boot Learning Journey ??
Today, I took my first step towards building real-world applications by creating a Spring Boot Hello World project!
Here’s what I accomplished:
To create a Spring Boot Hello World Example with the package structure com.example.Batch1, follow these steps based on the current Spring Boot version.
Step-by-Step Guide:
Step 1: Open Spring Initializr
Step 2: Provide Project Metadata
Step 3: Generate the Project
Step 4: Extract the ZIP File
Step 5: Import the Project into STS IDE
}
Step 6: Project Structure in STS
After importing, the project structure should appear in the Package Explorer like this:
领英推荐
Step 7: Create a Controller Class
package com.example.Batch1;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/Batch1")
public class Helloworld {
@GetMapping
public String Hello() {
return "Hello World ";
}
}
Step 8: Run the Application
Run the Batch1Application.java file.
Batch1Application.java
package com.example.Batch1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Batch1Application {
public static void main(String[] args) {
SpringApplication.run(Batch1Application.class, args);
}
}
When the application runs successfully, it shows a massage in the console, as shown in the following figure.
Step 9:Test the Application
Open the browser and invoke the URL https://localhost:8080/Batch1. It returns a String that we have specified in the Controller.