Spring Boot Hello world using Intellij Idea

Spring Boot Hello World Using IntelliJ IDEA | Step-by-Step Tutorial

Spring Boot Hello World Using IntelliJ IDEA

Author: Deep Singh | Category: Java, Spring Boot, IntelliJ IDEA

Introduction

In this tutorial, you'll learn how to create your very first Spring Boot Hello World application using IntelliJ IDEA and Spring Initializr. This beginner-friendly guide walks you through every step — from downloading the IDE to testing the running REST endpoint in your browser.

By the end, you'll have a working Spring Boot application that responds with "Hello World Example" when accessed via a web browser.

Step 1: Download and Install IntelliJ IDEA

First, download and install IntelliJ IDEA on your machine:

IntelliJ IDEA Download Here

IntelliJ IDEA download page showing Ultimate and Community editions
Figure 1: IntelliJ IDEA download page

Step 2: Open Spring Initializr

After installing IntelliJ IDEA, open Spring Initializr to generate your Maven project:

Spring Initializr Download Here

Spring Initializr web interface for generating a new Spring Boot project
Figure 2: Spring Initializr web interface

Step 3: Configure Project and Add Dependencies

Change the Group ID, Artifact ID, and Package Name according to your project. Then, from the top-right corner, add the Spring Web dependency and click Generate:

Configuring Spring Initializr project metadata and adding Spring Web dependency
Figure 3: Configure project and add Spring Web dependency

Step 4: Open the Project in IntelliJ IDEA

After downloading your project, extract it. Then in IntelliJ IDEA, select File → Open:

Selecting File menu and Open option in IntelliJ IDEA
Figure 4: File → Open in IntelliJ IDEA

Then select the extracted project folder:

Selecting the extracted Spring Boot project folder in IntelliJ IDEA
Figure 5: Select the extracted project folder

Step 5: Project Structure

Once the project finishes loading, your project structure will look like this:

Spring Boot project structure in IntelliJ IDEA showing src/main/java and application.properties
Figure 6: Spring Boot project structure

Step 6: Create HelloController.java

Create a new class inside the same package as HelloworldApplication and name it HelloController.java:

package com.deepsingh44.helloworld;

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

@RestController
public class HelloController {

    @GetMapping("/")
    public String welcome() {
        return "Hello World Example";
    }
}

Step 7: Run the Application

Right-click on HelloworldApplication and select Run:

Running the Spring Boot application from IntelliJ IDEA by clicking the Run button
Figure 7: Run the Spring Boot application

Step 8: Change Server Port (Optional)

If the default server port is already in use, you'll get a Port already in use error. To fix this, open application.properties and change the port:

server.port=8883

Step 9: Test in Browser

After the server starts successfully, open any browser and enter the URL (http://localhost:8080/ or your custom port) and hit Enter to see the result:

Browser displaying Hello World Example response from the Spring Boot application
Figure 8: Browser output — "Hello World Example"

Conclusion

Congratulations! You've successfully created and run your first Spring Boot Hello World application using IntelliJ IDEA. This is the foundation for building more complex Spring Boot applications.

Key takeaways:

  • Spring Initializr is the fastest way to bootstrap a Spring Boot project with the right dependencies.
  • @RestController combines @Controller and @ResponseBody, making it ideal for building REST endpoints.
  • @GetMapping("/") maps HTTP GET requests to the welcome() method.
  • Spring Boot's embedded Tomcat runs the app on port 8080 by default (configurable via server.port).
  • IntelliJ IDEA provides excellent tooling for Spring Boot, including run configurations and dependency management.

Next steps to explore:

  • Add more REST endpoints with @PostMapping, @PutMapping, and @DeleteMapping
  • Integrate a database with Spring Data JPA
  • Add Spring Security for authentication
  • Build a complete CRUD REST API
  • Package your app as a JAR and deploy it

This simple Hello World project is your gateway to the entire Spring Boot ecosystem. Happy coding!

No comments: