Skip to main content
This guide deploys a Spring Boot web application built with Maven, with a PostgreSQL database and Flyway migrations that run before each release. Qovery builds the image from your Dockerfile and runs it on a Kubernetes cluster in your own cloud account.
No configuration file in your repository. Qovery does not read a qovery.yml, .qovery.yml or .qovery.toml, and there is no qovery init. Projects, environments and services are created in the Console, with qovery api, or with Terraform. For the full path from a repository to a running app with commands only, see Deploy with the CLI and API.

Prerequisites

  • A Spring Boot application in a GitHub, GitLab or Bitbucket repository, with the Maven wrapper (mvnw and the .mvn folder) committed.
  • A Qovery account and a cluster: create one in your cloud account, connect your own cluster, or try it on your laptop.
  • These dependencies: the Spring Web, Actuator, JDBC (or Data JPA) and Flyway starters, org.postgresql:postgresql and org.flywaydb:flyway-database-postgresql. Spring Initializr adds them when you pick Spring Web, Spring Boot Actuator, JDBC API, Flyway Migration and PostgreSQL Driver.

Prepare the application

Read the port from PORT, trust the ingress headers, turn on the health probes, and turn Flyway off at startup, because a lifecycle job runs it:
src/main/resources/application.properties
Spring Boot expects a JDBC URL, with the user and password apart, while DATABASE_URL holds a postgresql://user:password@host:port/database URL. This configuration class builds the data source from it. Flyway uses the same data source:
src/main/java/com/example/demo/DataSourceConfig.java
Replace com.example.demo with your package. Put the migrations in src/main/resources/db/migration, named in the Flyway format, for example V1__create_items.sql.

Add a production Dockerfile

Create a Dockerfile at the root of the repository:
Dockerfile
  • The first stage builds the jar with the official eclipse-temurin:25-jdk image, the second runs it on eclipse-temurin:25-jre, which has no compiler. Match the Java version to the java.version of your pom.xml.
  • Downloading the dependencies before copying src keeps that layer cached when only the code changes.
  • -XX:MaxRAMPercentage=75 sizes the heap from the memory limit of the container, instead of the memory of the node.
  • The container runs as a non-root user.
  • CMD ["java", "-jar", "app.jar"] starts the JVM directly, so it receives the stop signal.
With Gradle, build with ./gradlew bootJar and copy the jar from build/libs. Add a .dockerignore with at least .git and target.

Port and health check

The application listens on port 8080. Actuator exposes two probe endpoints, which answer 200 when the state is up and 503 when it is not:
  • GET /actuator/health/readiness for the readiness probe, which tells Kubernetes when the application can take traffic.
  • GET /actuator/health/liveness for the liveness probe, which tells Kubernetes when to restart it.
Keep them apart: during a graceful shutdown, readiness turns down while liveness stays up, so a liveness probe on the readiness path would restart a pod that is only draining.

Connect PostgreSQL

The application and the migration job read the connection string from DATABASE_URL. Create PostgreSQL, then expose its connection string under that name at the environment scope, so every service of the environment gets it.
  1. In the environment, click New Service and pick PostgreSQL. Keep the visibility private, then create and deploy it. See Create a Database.
  2. Open the Variables section of the environment, find the built-in variable QOVERY_POSTGRESQL_Z<ID>_DATABASE_URL_INTERNAL, select Create alias, and name it DATABASE_URL.
From the CLI, once the application exists:
This database runs as a container on your cluster, with no automated backups. Use it for development and testing.
See Aliases and Variable Interpolation for the rules.

Set the variables

Add the other variables your application reads, and mark keys and passwords as secrets. Spring Boot maps environment variables to properties, so SPRING_PROFILES_ACTIVE=prod sets spring.profiles.active.

Run the migrations

Run Flyway in a lifecycle job built from the same repository and Dockerfile, triggered on the Deploy event, with these CMD arguments:
The job starts the application without the web server and with Flyway on, applies the pending migrations, then exits. It runs once per deployment. In the default deployment pipeline, jobs run after the databases and before the applications, so the schema is up to date when the new code starts. Letting Flyway run when the application starts, the Spring Boot default, works for a single instance, but every instance then runs it at boot, and a failed migration leaves the application crashing in a loop.

Deploy

1

Create a project and an environment

Follow steps 1 and 2 of Deploy Your First Application. Pick the cluster the environment runs on.
2

Add PostgreSQL

Create the database and the DATABASE_URL variable as described in Connect PostgreSQL.
3

Create the application

In the environment, click New Service › Create application, select Git Repository, then your repository and branch. Leave Root Application Path empty unless the Dockerfile is in a subfolder.
4

Set the port

Add port 8080 with the protocol HTTP, and turn on Publicly Accessible. Qovery serves it over HTTPS on port 443.
5

Set the health checks

Set the readiness and liveness probes to type HTTP, path /actuator/health/readiness, port 8080. See Service Health Checks.
6

Add the variables

Click Create, without deploying yet. Then open the Variables section of the environment and add the other variables listed in Set the variables at the environment scope, so the migration job gets them too. DATABASE_URL already exists from the previous step. Mark keys and passwords as secrets.
7

Create the migration job

Click New Service › Create lifecycle job, select the same repository, branch and Dockerfile, and trigger it on the Deploy event (START) with the CMD arguments ["java", "-jar", "app.jar", "--spring.main.web-application-type=none", "--spring.flyway.enabled=true"]. Set the number of restarts to 0. See Run the migrations.
8

Deploy

Deploy the environment. Qovery deploys the database, then the job, then the application, builds the image from your Dockerfile and gives the application a URL on qovery.io. Follow the progress in the Deployment logs tab.
In the health checks step, then change the path of the liveness probe to /actuator/health/liveness.

Troubleshooting

The CLI commands below use the organization, project and environment selected with qovery context set. Run it first, or add --organization, --project and --environment to each command.
The application listens on another port than the one set in Qovery, or the probes are off. Check server.port=${PORT:8080} and management.endpoint.health.probes.enabled=true, and that the port in Qovery is 8080. A large application can take longer to start than the probe allows: raise the initial delay in Service Health Checks. Read the error lines with qovery environment deployment logs --environment "<env>" --service "<app>" --errors-only.
The heap does not fit in the memory of the container. Keep -XX:MaxRAMPercentage=75 and raise the memory of the application, or lower the percentage if the application uses a lot of memory outside the heap.
The migrations did not run against this database. Check that the job and the application read the same DATABASE_URL at the environment scope, and read the job output with qovery log --job "<job name>".
Something in the application keeps the JVM running without the web server, such as a scheduler or a message listener. Turn it off in the job with a property, for example with @ConditionalOnProperty on its configuration, and pass that property in the CMD arguments.
The wrapper lost its executable bit, which happens when the repository was committed from Windows. Run git update-index --chmod=+x mvnw, commit and push.
For other errors, see Diagnose a Failed Build or Deployment.

Next steps

Preview environments

Get a full copy of the environment for each pull request

Autoscaling

Set the number of instances and the resources

Auto deploy

Deploy on every push to the branch

Other frameworks

All framework guides