You are currently viewing How to Deploy Spring Boot Applications on Heroku: Step-by-Step Guide

How to Deploy Spring Boot Applications on Heroku: Step-by-Step Guide

In this tutorial, you’ll discover how to deploy and host your Spring Boot applications on Heroku, a popular cloud platform-as-a-service (PaaS) provider. Heroku offers a seamless deployment experience for Java applications, including Spring Boot projects. By following these steps, you can quickly get your Spring Boot app up and running on the web.

Prerequisites

Before you begin, ensure you have the following:

  • A Heroku account (sign up at Heroku)
  • JDK installed on your local machine
  • Maven or Gradle build tool installed
  • Spring Boot application ready for deployment

Step 1: Install Heroku CLI

First, you need to install the Heroku Command Line Interface (CLI) on your local machine. The CLI allows you to manage and deploy applications on Heroku directly from your terminal.

$ curl https://cli-assets.heroku.com/install.sh | sh

Verify the installation by running:

$ heroku --version

Step 2: Prepare Your Spring Boot Application

Ensure your Spring Boot application is ready for deployment. Make sure it’s configured to use an appropriate port and contains a Procfile for Heroku. The Procfile specifies the command to start your application.

Example Procfile:

web: java -jar target/my-spring-boot-app.jar

Step 3: Create a Heroku App

Navigate to your project directory in the terminal and log in to your Heroku account using the CLI:

$ heroku login

Create a new Heroku app:

$ heroku create

This command will generate a unique app name (or you can specify your own with heroku create <app-name>). Note the URL of your newly created app.

Step 4: Deploy Your Application

Now, it’s time to deploy your Spring Boot application to Heroku. Use Git to push your code to the Heroku remote repository:

$ git push heroku master

This command will trigger the deployment process. Heroku will automatically detect that it’s a Java application and will build and deploy it accordingly.

Step 5: Access Your Application

Once the deployment is complete, you can access your Spring Boot application by visiting the URL provided by Heroku or using:

$ heroku open

Step 6: Scale Your Application (Optional)

You can scale your application by adjusting the number of dynos (containers) running your app:

$ heroku ps:scale web=1

Conclusion

Congratulations! You have successfully deployed your Spring Boot application on Heroku. You can now share your app with others or continue to enhance its features. Heroku provides a robust platform for hosting and scaling your Java applications effortlessly.

Now, go ahead and explore the endless possibilities of deploying Spring Boot applications on Heroku!

Leave a Reply