Spring Boot Tutorial

Spring Boot - Software Setup and Configuration (STS/Eclipse/IntelliJ)

Prerequisite (Spring Core Concepts)

Spring Boot Core

Spring Boot with REST API

Spring Boot with Database and Data JPA

Spring Boot with Kafka

Spring Boot with AOP

How to Run Your First Spring Boot Application in IntelliJ IDEA?

IntelliJ IDEA provides great support for Spring Boot applications. Here's a step-by-step guide on how to run your first Spring Boot application using IntelliJ IDEA:

1. Install IntelliJ IDEA:

If you haven't already, download and install IntelliJ IDEA. While the Ultimate edition is paid and provides comprehensive support for Spring, the free Community edition can also run Spring Boot applications.

2. Generate a Spring Boot Project:

  • Visit the Spring Initializr website.
  • Choose your preferred build tool (Maven/Gradle).
  • Add necessary dependencies (For a basic web application, choose "Web" under "Spring Web").
  • Click "Generate" to download the ZIP file.

3. Import Project in IntelliJ IDEA:

  • Open IntelliJ IDEA.
  • Click on "Open or Import" on the start-up screen.
  • Navigate to the location where you extracted the ZIP file from Spring Initializr.
  • Choose the project directory and click "Open".

IntelliJ will recognize and import the project as a Maven or Gradle project based on your selection and download necessary dependencies.

4. Create a Simple Controller:

For this step, let's create a simple Spring Boot controller:

  • In the main package, create a new Java class named HelloController.
  • Add the following content:
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!";
    }
}

5. Run Your Application:

  • Navigate to the main class (the class with the @SpringBootApplication annotation).
  • Right-click on the file in the project explorer.
  • Choose "Run 'YourMainClassName'".
    • Alternatively, in the top right corner of the editor window, you'll see a green play button (▶️). Click on it to run the application.

6. Access Your Application:

Once the application starts successfully, open a web browser and go to:

http://localhost:8080/hello

You should see the message "Hello, Spring Boot!"

That's it! You've just run your first Spring Boot application in IntelliJ IDEA. You can now expand upon this foundation by adding more controllers, services, database connections, and so on.