Deploying Spring Boot application to Heroku with PostgreSql

In this article, I will talk about how we can easily deploy a Spring Boot application connected to PostgreSql to Heroku.Simply HerokuHeroku is a cloud computing application infrastructure service provider. It is a platform that allows you to deploy you…


This content originally appeared on Level Up Coding - Medium and was authored by Enes Gür

In this article, I will talk about how we can easily deploy a Spring Boot application connected to PostgreSql to Heroku.

Simply Heroku

Heroku is a cloud computing application infrastructure service provider. It is a platform that allows you to deploy your web-based applications deployed in languages such as Node.js, Ruby, Python, Java, PHP, Go, Scala, Clojure quickly and without the need for technical server setup knowledge.

Creating the Application

There will be an application that save records to PostgreSql with a REST service of type Http Post.

With Spring Initializr we create an application that uses the following dependencies and settings, then open this application in the IDE.

Since the application will have different settings in the local environment and the Heroku environment, I add a file called application-default.properties and define it as follows.

In order for the application to read the property file dynamically, I set the Application class as follows.

Then I simply added the classes that do the necessary operations under the entity, controller, service and repository modules. In order not to keep the article long, I do not include them here, you can take a look at the project from the GitHub link at the end of the article.

I tested the application in local environment via postman and got successful result.

The application is now ready to be deployed to Heroku.

First, we add a file called app.json to the application.

app.json is a manifest format for describing web apps. It declares environment variables, add-ons, and other information required to run an app on Heroku.

We create the app.json file as follows.

After deploying the application to the Heroku environment, we create the application-prod.properties file to set different configurations and add the following.

spring.datasource.url=DATABASE_URL, in field ${DATABASE_URL} will be given as value in heroku environment

Then, by saying buildJar from the Gradle tab, we create a file called libs in the build path in the application folder and add the jar of the application there.

Now we add the Procfile fileto the application.

With the Procfile file, we can show the target jar file of the application and make it based on the application-prod.properties configurations for the heroku environment.

The Procfile file is set as follows.

Finally, we create a file called system.properties on the application path and specify our java version there.

Since we will deploy our application to Heroku environment via GitHub, we push the application to GitHub.

We register for the application at Heroku free of charge and continue with the free deployment method.

A dashboard screen like the one below will greet you, since I have old projects, the dashboard area is full.

We continue by pressing the New button and then selecting Create new app.

We proceed by giving our application a unique name from the screen below.

Then we go to the Resources tab, select Heroku Postgres and add it to our application.

When we go to the Settings tab and view the configs, we see that the connection string of the PostgreSql database we just created in the Heroku environment is added to the DATABASE_URL key.

Now we will go to the Deploy tab and make the deployment settings. By clicking on the Connect to GitHub option, we indicate that we will deploy the application via GitHub. After pairing Heroku with GitHub, we select our repo as follows.

If we want to have automatic deploy in every change to be made in the master branch, we must press the Enable Automatic Deploys button.

If we want to have automatic deploy in every change to be made in the master branch, we must press the Enable Automatic Deploys button.

After the deployment is over, we get the url of the application from the Settings tab and send a request through Postman.

We saw that our dummy record has successfully added.

Conclusion

In this article, we have seen how we easily deploy a Spring Boot application to Heroku environment, how we add PostgreSql to the Heroku environment and connect it to the application.

You can find the source code of the application here.

See you in the next articles.


Deploying Spring Boot application to Heroku with PostgreSql was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Enes Gür


Print Share Comment Cite Upload Translate Updates
APA

Enes Gür | Sciencx (2022-01-04T14:59:29+00:00) Deploying Spring Boot application to Heroku with PostgreSql. Retrieved from https://www.scien.cx/2022/01/04/deploying-spring-boot-application-to-heroku-with-postgresql/

MLA
" » Deploying Spring Boot application to Heroku with PostgreSql." Enes Gür | Sciencx - Tuesday January 4, 2022, https://www.scien.cx/2022/01/04/deploying-spring-boot-application-to-heroku-with-postgresql/
HARVARD
Enes Gür | Sciencx Tuesday January 4, 2022 » Deploying Spring Boot application to Heroku with PostgreSql., viewed ,<https://www.scien.cx/2022/01/04/deploying-spring-boot-application-to-heroku-with-postgresql/>
VANCOUVER
Enes Gür | Sciencx - » Deploying Spring Boot application to Heroku with PostgreSql. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/04/deploying-spring-boot-application-to-heroku-with-postgresql/
CHICAGO
" » Deploying Spring Boot application to Heroku with PostgreSql." Enes Gür | Sciencx - Accessed . https://www.scien.cx/2022/01/04/deploying-spring-boot-application-to-heroku-with-postgresql/
IEEE
" » Deploying Spring Boot application to Heroku with PostgreSql." Enes Gür | Sciencx [Online]. Available: https://www.scien.cx/2022/01/04/deploying-spring-boot-application-to-heroku-with-postgresql/. [Accessed: ]
rf:citation
» Deploying Spring Boot application to Heroku with PostgreSql | Enes Gür | Sciencx | https://www.scien.cx/2022/01/04/deploying-spring-boot-application-to-heroku-with-postgresql/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.