Last updated: 2024-12-08

  1. Learn
  2. Spring Boot
  3. Heroku Deployment

Deploying Spring Boot apps to Heroku

Heroku is one of the best options for deploying a Spring Boot app. Together with GitHub actions, you have an affordable and minimalist setup for automatically rolling out new versions. The following setup can be prepared directly using the Deployment option of your Bootify project.

Advantages and setup of Heroku

With Eco or Basic Dyno, you can run your application on Heroku from $5 per month. Other providers also offer low-cost options, but Heroku allows to use the hard drive as swap space. This means that even complex applications do not immediately reach the memory limit (0.5 GB) – with other providers, you would need to choose 1 GB of memory, which would be more expensive.

As a Platform-as-a-Service platform, Heroku can be configured directly on the website. For example, automatic certificate management for HTTPS connections can be activated. There are numerous add-ons available if required, but you can also connect any external providers, e.g. to use Supabase as a free Postgres database. Bootify's generated applications use the environment variable JDBC_DATABASE_URL (among others) for the database connection. These variables can be specified as environment variable at Heroku and are automatically used by the Spring Boot app when it starts.

Procfile used by Heroku

The files Procfile and system.properties should be located in the root directory of your source code. These are used to configure parameters for execution (such as the prod profile) and the Java version. The JAVA_OPTS can also be provided as an environment variable for the Heroku app as well - I recommend using -Xms128m -Xmx256m -Xss256k -XX:+UseSerialGC -XX:+UseContainerSupport -XX:+UseCompressedOops -XX:+ExitOnOutOfMemoryError for small dynos.

GitHub actions

If you use a GitHub repository for your code, you can also use GitHub Actions for deployment at no additional cost. A file named .github/workflows/deploy.yml is automatically recognized in the repository and executed according to its contents.

Example workflow for deploying a Gradle app to Heroku

In the GitHub repository settings, HEROKU_API_KEY and HEROKU_APP_NAME should be stored as secrets so that they can be picked up by the pipeline. With this setup, deployment to Heroku is performed automatically as soon as a change is made to the main branch.

Using Bootify, a Spring Boot app can be created directly in the browser. Already included in the Free plan, you can select Heroku via GitHub actions as a deployment option. This makes the complete setup immediately available.

Start Project
No registration required