Deploy Spring Boot App On Heroku


Author - FrugalisMinds

Deploy Spring Boot App On Heroku:-

Heroku is a platform as a service (PaaS) that developers use to deploy, manage and run apps on the cloud. There are a wide range of programming languages supported on Heroku platform.

In this article, you are going to see How to deploy Spring Boot app on Heroku with step by step guide.There are different ways to Deploy Spring boot app on Heroku and we are going to see a couple of convenient ways.

Project Structure Of Spring Boot App:-

Let's go ahead and create a simple app using spring initializr. Please follow the steps to create a simple spring boot app.

  1. Enter Group name as **com.frugalis**
  2. Enter artifact id as **SpringHeroku**.
  3. Click on Generate and import in your favorite IDE.

Now let's go ahead and write a simple controller as below, we are now ready with a simple app to deploy spring boot app on Heroku. Please have a look at one of our blog post to Create Rest Services Using Spring Boot.

1.Deploy Spring Boot App On Heroku Using Heroku-CLI:-

First of all, you need to login to Heroku account. If you don’t have one, you can create it from Heroku’s Signup Page.We are going to use Heroku CLI and Git. Let's follow the steps now to deploy.

1.1 Download And Install Heroku CLI:-

Heroku CLI is a command line tool that helps to manage Heroku apps using the terminal. Please Download Heroku CLI and follow the instructions to install it on your computer.

1.2 Create Heroku App:-

Navigate to your Heroku dashboard by using the Dashboard link. Click on New button on right most corner and click on Create New App button.

Heroku Dashboard

You will get something like this below,

Spring Boot App On Heroku

Please enter the app name and click on create an app. Please note down the app name you entered. It will take you to Heroku app and the app page looks like below.

Spring Boot Heroku Deploy

1.3 Login to Heroku CLI:-

If you haven't already, log in to your Heroku account.P lease open command prompt/terminal and enter the following command.

$ heroku login

You will be prompted to enter your Heroku account’s credentials.

Enter your Heroku credentials:
Password: \*\*\*\*\*\*\*\*\*
Logged in as

1.4 Deploy Spring Boot App On Heroku using Heroku Git:-

Please navigate to your Spring Boot project and execute the following list of commands sequentially.

Deploy Spring Boot On Heroku

We have now deployed our app on Heroku. Here frugalisapp  is the app name. You can get these commands in  app page under deploy section. You can open deployed app using Herok by executing the command .

$ heroku open

2. Deploy Spring Boot App Using Jar File:-

Before going on to the details, Let's look at few of the important plugins and install those . We are going to deal with two plugins Heroku Repo and Heroku CLI Deploy respectively.

Let's clean the cache and reset the app using Heroku repo.

$ heroku repo:gc -a appname
$ heroku repo:reset -a appname

Now let's deploy our Spring Boot project using Heroku CLI Deploy plugin.

Open from src/main/java/resources/

Please add following line below.


Navigate to Spring project folder and run.

$mvn clean package

Now run deploy command from your project directory.

$ heroku deploy:jar target/SpringHeroku-0.0.1-SNAPSHOT.jar --app <APP-NAME>

3. Deploy Spring Boot App On Heroku Using Procfile:-

We are going to add a Procfile in our spring boot app like below

web: java -Dserver.port=$PORT $JAVA\_OPTS -jar target/\*.jar

Now execute the deploy plugin again as below:-

$ heroku deploy:jar target/SpringHeroku-0.0.1-SNAPSHOT.jar --app <APP-NAME>

Drop us an Email With Subject Help On Spring Boot heroku if you want our team to help you on deploying any Spring boot App on heroku !! Free !!!!!!

Download Code

Related Links :-

CRUD Rest API With Spring Web-Flux Reactive Programming with Spring 5

Creating REST Service with Spring Boot

CRUD Rest Service With Spring Boot and JPA

Spring Boot Profiling – Configure for Different Environments