?? Day 8: My Spring Boot Learning Journey ??

?? 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

  1. Open Spring Initializr.

Step 2: Provide Project Metadata

  • Group: com.example
  • Artifact: Batch1
  • Name: Batch1
  • Description: A Spring Boot Hello World Example
  • Package name: com.example.Batch1
  • Packaging: Jar
  • Java version: 1.8 or higher (Java 11/17 recommended)
  • Dependencies: Select Spring Web.

Step 3: Generate the Project

  1. Click Generate. This will download a .zip file containing the base Spring Boot project.


Step 4: Extract the ZIP File

  1. Extract the ZIP file to your desired location.

Step 5: Import the Project into STS IDE

  1. In Spring Tool Suite (STS), go to FileImport.
  2. Select Existing Maven Projects and click Next.
  3. Browse to the folder where you extracted the .zip file and select the project folder.
  4. Click Finish to import the project into your 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

  1. Right-click on the src/main/java/com/example/Batch1 folder, and select NewPackage. Name the package controller.
  2. Right-click on the controller package, and select NewClass. Name the class HelloWorld.java

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.



要查看或添加评论,请登录

Sakthi Kumar M的更多文章

社区洞察

其他会员也浏览了