How to Run Spring Boot Application?

Spring Boot is built on the top of Spring and contains all the features of Spring. And it is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and setup. Spring Boot is a microservice-based framework and making a production-ready application in it takes very little time. Following are some of the features of Spring Boot:

  • It allows for avoiding heavy configuration of XML which is present in spring.
  • It provides easy maintenance and creation of REST endpoints.
  • It includes an embedded Tomcat server.
  • Deployment is very easy; war and jar files can be easily deployed in the Tomcat server.

For more information, please refer to this article: Introduction to Spring Boot

Generally, to develop a Spring Boot Application we choose Eclipse, Spring Tool Suite, and IntelliJ IDEA IDE. So, in this article, we are going to run our application in these 3 IDEs. 

Run Spring Boot Application in Eclipse IDE

The Eclipse IDE is famous for the Java Integrated Development Environment (IDE), but it has a number of pretty cool IDEs, including the C/C++ IDE, JavaScript/TypeScript IDE, PHP IDE, and more. 

Step by Step Implementation:

  1. Create and set up Spring Boot project.
  2. Add the spring-web dependency in your pom.xml file.
  3. Create one package and name the package as “controller”.
  4. Run the Spring Boot application.

Step 1: Create and Setup Spring Boot Project in Eclipse IDE

One should know how to create and set up Spring Boot Project in Eclipse IDE and create your first Spring Boot Application in Eclipse IDE. 

Step 2: Add the spring-web dependency in your pom.xml file. Go to the pom.xml file inside your project and add the following spring-web dependency.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

Step 3: In your project create one package and name the package as “controller”. In the controller package create a class and name it as DemoController. Below is the code for the DemoController.java file.

Java
package com.example.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class DemoController {

    @RequestMapping("/hello")
    @ResponseBody
    public String helloWorld()
    {
        return "Hello World!";
    }
}