Spring Framework Tutorial

Software Setup and Configuration (STS/Eclipse/IntelliJ)

Core Spring

Spring Annotations

Spring Data

Spring JDBC

Spring Security

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

Running a Spring Boot application in IntelliJ IDEA is straightforward due to the excellent integration between the two. Here's a step-by-step guide to run your first Spring Boot application in IntelliJ IDEA:

  1. Open the Project:

    • If you have an existing Spring Boot project, open IntelliJ IDEA.
    • Click on File > Open, navigate to your project's root directory, and click OK.
  2. Maven/Gradle Dependencies:

    Once the project is opened, IntelliJ IDEA will automatically start downloading the required dependencies if it's a Maven or Gradle project. You can see the progress at the bottom of the IDE. If for some reason it doesn't start:

    • For Maven: Right-click on the pom.xml file > Reload Project.
    • For Gradle: Right-click on the build.gradle file > Reload Project.
  3. Locate the Main Class:

    Navigate to the main application class. This is the class with the @SpringBootApplication annotation. It contains the main method which looks like this:

    public static void main(String[] args) {
        SpringApplication.run(YourApplicationName.class, args);
    }
    
  4. Run the Application:

    • Right-click anywhere within the main class editor.
    • From the context menu, select Run 'YourApplicationName'.

    Alternatively, in the top-right corner of the editor, you'll notice a green play button (▶️) beside the main method. You can click that button to run the application.

  5. Check the Console:

    After you run the application, switch to the Run window at the bottom of IntelliJ IDEA. Here, you can see the console output of your application. If everything is set up correctly, you'll see log messages from Spring, and towards the end, something similar to:

    Started YourApplicationName in X seconds (JVM running for Y).
    

    This indicates that the Spring Boot application has started successfully.

  6. Access the Application:

    If your Spring Boot application has a web component (e.g., a REST API or a web frontend), you can now access it by opening a web browser and navigating to:

    http://localhost:8080
    

    Change the port number if you've configured a different one in application.properties or application.yml.

  7. Stopping the Application:

    To stop the application, go to the Run window at the bottom and click the red square stop button (⏹️).

Remember, IntelliJ IDEA provides many tools and features to make Spring Boot development easier, such as autocompletion, integrated debugging, database tools, and more. Familiarizing yourself with these features will help streamline your development process.

  1. Executing Your First Spring Boot RESTful Service in IntelliJ:

    • Description: Create and run your first Spring Boot RESTful service in IntelliJ IDEA.
    • Code: (Example code for a simple RESTful service)
      @RestController
      public class HelloWorldController {
          @GetMapping("/hello")
          public String hello() {
              return "Hello, World!";
          }
      }