The Wayback Machine - https://web.archive.org/web/20241009183638/https://www.geeksforgeeks.org/how-to-run-spring-boot-application/
Open In App

How to Run Spring Boot Application?

Last Updated : 12 Mar, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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!";
    }
}

We have used the below annotations in our controller layer. Here in this example, the URI path is /hello.

  • @Controller: This is used to specify the controller.
  • @RequestMapping: This is used to map to the Spring MVC controller method.
  • @ResponseBody: Used to bind the HTTP response body with a domain object in the return type.

Now, our controller is ready. Let’s run our application inside the DemoApplication.java file. There is no need to change anything inside the DemoApplication.java file.  

Java
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

Step 4: Run the Spring Boot Application

To run the application, click on the green icon as seen in the below image. 

Run the application

After successfully running the application, you can see the console as shown in the below image. Your Tomcat server started on port 8989. 

Application Started

Try this Tomcat URL, which is running on http://localhost:8989/hello 

Output in Browser

Run Spring Boot Application in IntelliJ IDEA

IntelliJ IDEA is an integrated development environment (IDE) written in Java. It is used for developing computer software. This IDE is developed by Jetbrains and is available as an Apache 2 Licensed community edition and a commercial edition. It is an intelligent, context-aware IDE for working with Java and other JVM languages like Kotlin, Scala, and Groovy on all sorts of applications. Additionally, IntelliJ IDEA Ultimate can help you develop full-stack web applications, thanks to its powerful integrated tools, support for JavaScript and related technologies, and advanced support for popular frameworks like Spring, Spring Boot, Jakarta EE, Micronaut, Quarkus, Helidon.  So in this article, we are going to discuss how to run your first spring boot application in IntelliJ IDEA. 

Prerequisite: Download and Install IntelliJ IDEA in your system. Please refer to this article Step by Step guide to install Intellij Idea to Install IntelliJ IDEA in Your System.

Procedure:

  1. Create and Setup Spring Boot Project
  2. Creating or importing the spring boot project a file name Application.java
  3. Run the Spring Boot Application
  4. Tomcat server will be started.
  5. Re-run the application again

Step 1: Create and Setup Spring Boot Project in IntelliJ IDEA

You may refer to this article How to Create and Setup Spring Boot Project in IntelliJ IDEA and create your first Spring Boot Application in IntelliJ IDEA.

Step 2: After successfully creating or importing the spring boot project a file name Application.java (Here DemoApplication) will be created automatically and this is your entry point. You can consider it as the main method of a Spring Boot application. 

Main Class File

Step 3: Run the Spring Boot Application

Method 1: To run this application now Right-click on the Application.java > Run “DemoApplication.main()” as shown in the below image. or you may type the shortcut key combination (Ctrl + Shift + F10) to run the application. 

Run Application

Method 2: Directly click on the green color triangle button as shown in the below image then choose Run ‘DemoApplication.main()’. 

Right click then Run

Step 4: After successfully running the application, you can see the console as shown in the below image. Your Tomcat server started on port 8080. 

Application Started

The default port of the Tomcat server is 8080 and can be changed in the application.properties file by using this following line of code.

server.port=8989

Step 5: Now re-run the application again and you can see that your Tomcat server has started on the port that you have given, like in the below image.

application.properties

You can access the output screen from the following URL: http://localhost:8989/. Note that at last you need to provide your port number. 
 

Run Spring Boot Application in Spring Tool Suite

Spring Tool Suite (STS) is a Java IDE tailored for developing Spring-based enterprise applications. It is easier, faster, and more convenient. And most importantly it is based on the Eclipse IDE. STS is free, open-source, and powered by VMware. Spring Tools 4 is the next generation of Spring tooling for the favorite coding environment. Largely rebuilt from scratch, it provides world-class support for developing Spring-based enterprise applications, whether you prefer Eclipse, Visual Studio Code, or Theia IDE. So in this article, we are going to discuss how to run your first spring boot application in STS. 

Prerequisite: Download and Install Spring Tool Suite (Spring Tools 4 for Eclipse) IDE in your system. You may refer to this article: How to Download and Install Spring Tool Suite (Spring Tools 4 for Eclipse) IDE?

Procedure:

  1. Create Spring Boot project in Spring Tool Suite
  2. Import the Project into STS IDE
  3. An entry file named Application file will be created for STS
  4. Run the application on the server.

Step 1: Create Your Spring Boot Project in Spring Tool Suite

You may refer to this article How to Create and Setup Spring Boot Project in Spring Tool Suite and create your first Spring Boot Application. Or you may Create Your Spring Boot Project in Spring Initializer and import the project into your STS IDE. Please refer to this article to Create Spring Boot Project in Spring Initializer.

Step 2: How to Import the Project into Your STS IDE?

2.1: Go to your STS IDE > File > Open Project from File System as shown in the below image. 

Open Project

2.2: A pop-up window will occur like the following. Here you have to choose the directory that has been generated while creating the Spring Boot project in Spring Initializer. And then click on the Finish button.  

Import Project

Step 3: After successfully creating or importing the spring boot project a file name Application.java (Here DemoApplication) will be created automatically and this is your entry point. You can consider it as the main method of a Spring Boot application. 

Main Class

Step 4: In order to run this application now, Right-click on the Application.java > Run As > Spring Boot App as shown in the below image.

Run Main Method

Step 5: After successfully running the application, you can see the console where the Tomcat server starts on default port number 8080 as shown in the below image. 

Application Started

Now geeks you must be wondering about what to do if we do not want it to be run on the default port number, that is if we do not want the application to be run on the default port of the Tomcat server, which is 8080. We can change the port number in the application.properties file by using the following line of code as follows:

server.port=8989

A. Now re-run the application again and you can see Your Tomcat server started on the port that you have given like the below image.

Tomcat Server Started

B. If you are encountered with the following error then it is highly recommended that you should change your port number.

Change Port Number

Note: You can access the output screen in the following URL: http://localhost:8080/. Note that at last provide your port number. 



Previous Article
Next Article

Similar Reads

How to Run Your First Spring Boot Application in Spring Tool Suite?
Spring Tool Suite (STS) is a java IDE tailored for developing Spring-based enterprise applications. It is easier, faster, and more convenient. And most importantly it is based on Eclipse IDE. STS is free, open-source, and powered by VMware. Spring Tools 4 is the next generation of Spring tooling for the favorite coding environment. Largely rebuilt
3 min read
Migrate Application From Spring Boot 2 to Spring Boot 3
With the release of Spring Boot 3, significant changes and improvements have been introduced, particularly around Jakarta EE compliance, Java 17 support, and GraalVM native images. If you are using Spring Boot 2 and are considering migrating to Spring Boot 3, this article will walk you through the necessary steps, considerations, and potential pitf
5 min read
How to Create a Spring Boot Project in Spring Initializr and Run it in IntelliJ IDEA?
Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using Java is that it tries to connect every concept in the language to the real world with the help
3 min read
How to Run Your First Spring Boot Application in IntelliJ IDEA?
IntelliJ IDEA is an integrated development environment(IDE) written in Java. It is used for developing computer software. This IDE is developed by Jetbrains and is available as an Apache 2 Licensed community edition and a commercial edition. It is an intelligent, context-aware IDE for working with Java and other JVM languages like Kotlin, Scala, an
3 min read
How to Run Your First Spring Boot Application in Eclipse IDE?
Spring Boot is built on the top of the spring and contains all the features of spring. And 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
3 min read
Difference Between Spring Boot Starter Web and Spring Boot Starter Tomcat
Spring Boot is built on the top of the spring and contains all the features of spring. And 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
3 min read
Spring Boot – Handling Background Tasks with Spring Boot
Efficiently handling background tasks with Spring Boot is important for providing a smooth user experience and optimizing resource utilization. Background tasks refer to operations that are performed asynchronously or in the background, allowing the main application to continue processing other requests. In a Spring Boot application, background tas
5 min read
Spring Boot – Using Spring Boot with Apache Camel
Apache Camel and Spring Boot are two powerful frameworks that can be seamlessly integrated to build robust, scalable, and efficient applications. Apache Camel is an open-source integration framework that provides an extensive range of components and connectors, enabling developers to integrate different systems, APIs, and applications. It simplifie
5 min read
Spring Boot – Setting Up a Spring Boot Project with Gradle
Spring Boot is a Java framework designed to simplify the development of stand-alone, production-ready Spring applications with minimal setup and configuration. It simplifies the setup and development of new Spring applications, reducing boilerplate code. In this article, we will guide you through setting up a Spring Boot project using Gradle, a wid
4 min read
Spring Boot - Customizing Spring Boot Starter
Spring Boot Starters are specialized project types designed to encapsulate and distribute common functionality, simplifying the setup of Spring Boot applications. Official starters, like spring-boot-starter-web and spring-boot-starter-data-jpa, bundle dependencies, configurations, and pre-built beans for specific use cases. Creating a custom Spring
6 min read
Spring Boot - Spring JDBC vs Spring Data JDBC
Spring JDBC Spring can perform JDBC operations by having connectivity with any one of jars of RDBMS like MySQL, Oracle, or SQL Server, etc., For example, if we are connecting with MySQL, then we need to connect "mysql-connector-java". Let us see how a pom.xml file of a maven project looks like. C/C++ Code <?xml version="1.0" encoding=
4 min read
Spring vs Spring Boot vs Spring MVC
Are you ready to dive into the exciting world of Java development? Whether you're a seasoned pro or just starting out, this article is your gateway to mastering the top frameworks and technologies in Java development. We'll explore the Spring framework, known for its versatility and lightweight nature, making it perfect for enterprise-level softwar
8 min read
Configuring Multiple Spring Batch Jobs in a Spring Boot Application
Spring Batch serves as a robust framework within the Spring ecosystem, specifically tailored for managing batch processing tasks efficiently. It's designed to tackle big data jobs efficiently and comes with handy tools to make batch application development a breeze. In the context of a Spring Boot application, setting up multiple Spring Batch jobs
10 min read
Spring Boot - application.yml/application.yaml File
Spring is widely used for creating scalable applications. For web applications Spring provides. In Spring Boot, whenever we create a new Spring Boot Application in spring starter, or inside an IDE (Eclipse or STS) a file is located inside the src/main/resources folder named as application.properties file which is shown in the below media: So in a s
4 min read
How to Convert application.properties to application.yml for Spring Boot?
Spring Boot allows us to configure application properties in two formats that are application.properties and application.yml. Both serve the same purpose of configuring application settings such as database connections, server ports, and framework-specific configurations. Many developers prefer YAML (.yml) due to its human-readable format and bette
7 min read
How to Run a CommandLineRunner Bean Conditionally in Spring Boot?
In Spring Boot, CommandLineRunner is an interface used to execute code once the application startup is complete. This feature is especially useful for running initialization logic or checks right after the application starts. However, there may be situations where you want to run the CommandLineRunner implementation conditionally based on certain f
3 min read
Create and Run Your First Spring MVC Controller in Eclipse/Spring Tool Suite
Spring MVC framework enables separation of modules namely Model, View, and Controller, and seamlessly handles the application integration. This enables the developer to create complex applications also using plain java classes. The model object can be passed between view and controller using maps. In this article, we will see how to set up a Spring
5 min read
Spring Boot | How to access database using Spring Data JPA
Spring Data JPA is a method to implement JPA repositories to add the data access layer in applications easily. CRUD stands for create, retrieve, update, delete which are the possible operations which can be performed in a database. In this article, we will see an example of how to access data from a database(MySQL for this article) in a spring boot
4 min read
How to Create and Setup Spring Boot Project in Spring Tool Suite?
Spring Boot is built on the top of the spring and contains all the features of spring. And 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
3 min read
How to Make a Project Using Spring Boot, MySQL, Spring Data JPA, and Maven?
For the sample project, below mentioned tools got used Java 8Eclipse IDE for developmentHibernate ORM, Spring framework with Spring Data JPAMySQL database, MySQL Connector Java as JDBC driver.Example Project Using Spring Boot, MySQL, Spring Data JPA, and Maven Project Structure: As this is getting prepared as a maven project, all dependencies are s
4 min read
What's New in Spring 6 and Spring Boot 3?
Spring and Spring Boot are two of the most popular Java frameworks used by developers worldwide. The Spring team is continuously working on improving and enhancing the frameworks with each new major release. Spring 6 and Spring Boot 3 are expected to bring in significant new features and changes that will further boost development with these techno
5 min read
Java Spring Boot Microservices - Integration of Eureka, Feign & Spring Cloud Load Balancer
Microservices are small, loosely coupled distributed services. Microservices architecture evolved as a solution to the scalability, independently deployable, and innovation challenges with Monolithic Architecture. It provides us to take a big application and break it into efficiently manageable small components with some specified responsibilities.
13 min read
Spring Cloud Vs Spring Boot Actuator
Spring CloudSpring Cloud's main purpose is to give tools and services for managing and making distributed systems, especially in a microservices architecture. The developer wants to speed up the process of building patterns in distributed systems, these tools can fulfill their requirement. They include almost all from the management of configuratio
5 min read
Spring Boot - Reactive Programming Using Spring Webflux Framework
In this article, we will explore React programming in Spring Boot, Reactive programming is an asynchronous, non-blocking programming paradigm for developing highly responsive applications that react to external stimuli. What is Reactive ProgrammingIn reactive programming, the flow of data is asynchronous through push-based publishers and subscriber
4 min read
Show SQL from Spring Data JPA/Hibernate in Spring Boot
In Spring Boot, Spring Data JPA is part of the larger Spring Data Project that can simplify the development of the data access layers in the spring applications using the Java Persistence API and it can provide a higher-level abstraction over the JPA API. It can reduce the boilerplate code and make it easier to work with the database. Spring Data J
6 min read
Spring Boot - Spring Data JPA
Spring Data JPA or JPA stands for Java Persistence API, so before looking into that, we must know about ORM (Object Relation Mapping). So Object relation mapping is simply the process of persisting any java object directly into a database table. Usually, the name of the object being persisted becomes the name of the table, and each field within tha
6 min read
Properties with Spring and Spring Boot
Java-based applications using the Spring framework and its evolution into the Spring Boot and the properties play a crucial role in configuring the various aspects of the application. Properties can allow the developers to externalize the configuration settings from the code. Understanding how to work with properties in the Spring and Spring Boot i
4 min read
Implementing CORS in Spring Boot with Spring Security
CORS issue is one of the common issues being faced in web development. We are here going to configure CORS in our backend application built using Spring Boot and Spring security, being used for security purpose. Before going to fix the issue, lets understand what CORS is and how it works and why browsers show error while sending CORS request. What
6 min read
Spring Boot 3.0 - JWT Authentication with Spring Security using MySQL Database
In Spring Security 5.7.0, the spring team deprecated the WebSecurityConfigurerAdapter, as they encourage users to move towards a component-based security configuration. Spring Boot 3.0 has come with many changes in Spring Security . In this article, we'll learn how to implement JWT authentication and authorization in a Spring Boot 3.0 application u
9 min read
Spring Boot - Dependency Injection and Spring Beans
Spring Boot is a powerful framework for building RESTful APIs and microservices with minimal configuration. Two fundamental concepts within Spring Boot are Dependency Injection (DI) and Spring Beans. Dependency Injection is a design pattern used to implement Inversion of Control (IoC), allowing the framework to manage object creation and dependenci
6 min read
Article Tags :
Practice Tags :