In this final chapter in the series, you learn how to deploy a Spring Boot application on Heroku.
This chapter covers:
Vaadin production builds.
Configuring PostgreSQL for production.
Creating a Heroku account.
Installing the Heroku CLI.
Creating and deploying a Heroku application.
Vaadin can be deployed on any cloud providerYou can also deploy your application onto other cloud platforms. Read the Cloud Deployment tutorials for more options.
The pom.xml file includes a
production profile configuration that prepares an optimized build which is ready for production.
During development, the application has used an in-memory H2 database. This is convenient and works well for a single user. In production, you want to use something more robust and persistent. Heroku’s free tier supports PostgreSQL, so can configure your application to use that.
First, add the PostgreSQL dependency in the production profile of pom.xml:
<profile> <id>production</id> <!-- Omitted --> <dependencies> <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> </dependency> </dependencies> </profile>
Next, configure how JPA should handle schema generation. Add the following two properties to the end of application.properties.
Use the Heroku CLI to create and deploy your application.
Install the Heroku Java plugin:
heroku plugins:install java
The project uses Java 11, whereas Heroku expects Java 8 projects by default. To ensure that Heroku would run a Java 11 environment, create a system.properties file under the project’s root directory with the following content:
Create a new application. Replace APPNAME with a name of your choice. APPNAME is part of the URL, like https://APPNAME.herokuapp.com, so choose a name that is unique and easy to remember.
heroku create APPNAME
Enable the PostgreSQL plugin for the newly created application.
heroku addons:create heroku-postgresql -a APPNAME
Deploy the production-optimized JAR file you created in the previous section.
heroku deploy:jar target/flowcrmtutorial-1.0-SNAPSHOT.jar -a APPNAME
Open the application in your browser.
View the application logs, if anything went wrong.
heroku logs --tail
Congratulations. You have now built a full-stack PWA and deployed it to Heroku.
Now that you have a running application, you can use it to experiment further or as a foundation for your next idea.
Happy hacking, and ping us @vaadin on Twitter to show off the cool stuff you have built!