Deploying Spring Boot Application to Heroku

Initial Deployment with Heroku

git init

git add .

git commit -m "first commit"
git push heroku master

Database Configuration

SPRING_DATASOURCE_URL=
SPRING_DATASOURCE_USERNAME=
SPRING_DATASOURCE_PASSWORD=
SPRING_DATASOURCE_DRIVER-CLASS-NAME=org.postgresql.Driver
SPRING_DATASOURCE_TYPE=org.apache.tomcat.jdbc.pool.DataSource
SPRING_JPA_DATABASE-PLATFORM=org.hibernate.dialect.PostgreSQLDialect
compile('org.apache.tomcat:tomcat-jdbc:9.0.29')
compile('org.postgresql:postgresql:42.2.8')
Caused by: java.lang.RuntimeException: Driver org.postgresql.Driver claims to not accept jdbcUrl

Configuration of gradle to build jar file

2019-11-30T17:05:46.096985+00:00 heroku[api]: Deploy 291326d by xxx@gmail.com
2019-11-30T17:05:46.097021+00:00 heroku[api]: Release v9 created by xxx@gmail.com
2019-11-30T17:05:46.378258+00:00 heroku[slug-compiler]: Slug compilation started
2019-11-30T17:05:46.378269+00:00 heroku[slug-compiler]: Slug compilation finished
2019-11-30T17:05:46.755655+00:00 heroku[web.1]: State changed from crashed to starting
2019-11-30T17:05:53.121398+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=5000 -jar build/libs/myapp.jar`
2019-11-30T17:05:54.260741+00:00 app[web.1]: Error: Unable to access jarfile build/libs/myapp.jar
2019-11-30T17:05:54.784064+00:00 heroku[web.1]: State changed from starting to crashed
2019-11-30T17:05:54.773714+00:00 heroku[web.1]: Process exited with status 1
apply plugin: 'java'

task stage(type: Copy, dependsOn: [clean, build]) {
from jar.archivePath
into project.rootDir
rename {
'app.jar'
}
}
stage.mustRunAfter(clean)

clean.doLast {
project.file('app.jar').delete()
}

Setting up application.properties

# ====================================================================================
# = DATASOURCE
# ====================================================================================
spring.datasource.url=${SPRING_DATASOURCE_URL}
spring.datasource.username = ${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
spring.datasource.driver-class-name=${SPRING_DATASOURCE_DRIVER-CLASS-NAME}
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect = ${SPRING_JPA_DATABASE-PLATFORM}
spring.datasource.type=${SPRING_DATASOURCE_TYPE}
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
# ====================================================================================
# = Server SSL
# ====================================================================================
server.port = 7443
security.require-ssl=true

Setting up custom domain

Access the application

rentersfeedback

References

  1. Deploying Spring boot application to Heroku — deploy spring boot app
  2. Deploying Gradle application to Heroku — Gradle applications to Heroku
  3. Custom domains in Heroku — Custom domains in Heroku

--

--

--

Software Developer, Writer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to Build a Clubhouse Clone App with Flutter and Agora — A Tutorial by Perpetio: Part III

When VS code terminal doesn’t work

Animation of 2D sprites in Unity is fun :)

Shim layer C++

Asus mesh router

DevOps Is Not A Culture, Not Yet.

Learning Programming at the Absolutely Slowest Pace

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yogesh Mali

Yogesh Mali

Software Developer, Writer

More from Medium

Deploy Spring Boot App To AWS Elastic Beanstalk

How to deploy a Spring Boot Docker image at AWS ECS

Beginners guide to setting up Gitlab CI/CD with Docker for Spring Boot

Spring Boot Integration with MongoDB