Introduction:
If you're new to Java development using the Spring framework, building a "Hello World" application might seem like a small step, but it's a significant milestone in understanding the basics of Spring.
In this tutorial, we'll walk you through the process of creating your first Spring-based "Hello World" application using Spring Initializer within the Eclipse IDE.
By the end of this guide, you'll have a solid foundation for further exploring the Spring framework's capabilities.
Prerequisites:
Before we begin, make sure you have the following installed:
- Eclipse IDE
- Java Development Kit (JDK)
- Basic understanding of Java programming
Spring Starter Project:
Create a Spring Starter Project using a spring initializer.
Step 1: Visit site.
Visit https://start.spring.io/ and add the name of the project and dependencies.
Step 2: Add dependencies.
Add dependencies (click ADD DEPENDENCIES) according to your project requirement, here we will add only two dependencies that are required to our hello world application (Spring Web and Spring Web Service)
Step 3: Download ZIP
Click the generate and download zip file and save it on your system.
Step 4: Import ZIP
Import the .zip file into Eclipse.
Step 5: Finish Import
After completion of project importing go to the project main class under the src/main/java and click HelloInitializrApplication.java this is our main class that executes on the startup of the Spring application.
Step 7: Hello Application Program
Now, we can run the Hello world Program using the Controller class of Spring Boot
(a) Create the Controller class for map the request get from client and identify this class as a Controller.
(i). Go to HelloInitializrApplication.java under the src/main/java and right click on it and run as a Spring Boot App
(ii) Open Browser and enter the URL localhost:8080/Hello and press enter.
Creating Spring Project:
Step 1: Creating Project
Create a New Spring Boot Project
Open Eclipse and navigate to the File menu.
Select New > Spring Starter Project.
New Spring Starter Project
Choose a name for your project. Let's call it "HelloWorldApp".
Specify a Group name, Artifact name, and Package name for your project.
Select the desired version of Spring Boot. For this tutorial, we'll choose the latest version.
Add the Spring Web dependency by searching for it in the search bar and checking the checkbox.
Spring Web Dependency
Click Next and then Finish to create the project.
Step 2: Creating Controller
Create a Controller
Inside the src/main/java directory, navigate to your package (e.g., com.example.helloworldapp).
Right-click the package and select New > Class. Name the class HelloController.
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
Step 3: Run the Application
Right-click the HelloWorldAppApplication.java class in the src/main/java directory.
Select Run As > Java Application.
Step 4: Access the Application
Open a web browser and navigate to http://localhost:8080/hello.
You should see the text "Hello, World!" displayed on the page.
Finally:
Congratulations! You've successfully created a "Hello World" application using Spring Initializer in Eclipse. This simple project demonstrates the power of Spring Boot's auto-configuration and annotation-based programming model.
As you continue your journey into Spring development, you'll be able to build more complex applications and take advantage of Spring's wide range of features.
In this tutorial, we covered the following steps:
- Creating a new Spring Boot project using Spring Initializer in Eclipse.
- Adding the Spring Web dependency to enable web development.
- Creating a controller class to handle web requests.
- Running the Spring Boot application and accessing it through a web browser.
This is just the beginning of your Spring journey. You can explore more features, learn about dependency injection, data access, and various Spring modules to build robust and scalable applications. Happy coding!



