Deployment guide

Deploying a Spring Boot application on a VPS

Deploy on a VPS Cloud →

Tutorial

Deploying a Spring Boot application on a VPS

Development4 min read5 steps

Spring Boot remains the standard for enterprise Java APIs and microservices. Rather than paying for a PaaS billed by JVM memory, a VPS gives you full control over the heap, the connection pool and the monthly cost. Here is how to deploy your artifact cleanly in production.

Contents· Why Self-Host Spring Boot on a VPS?1/5
  1. 01Why Self-Host Spring Boot on a VPS?
  2. 02Concrete Benefits of a Self-Hosted Spring Boot
  3. 03Hardware and Software Requirements
  4. 04Deploy Spring Boot Step by Step
  5. 05Deploy Spring Boot in One Click from the ServOrbit Marketplace

Why Self-Host Spring Boot on a VPS?

Managed Java platforms bill per RAM slice and lock you into their JDK version, which complicates JVM tuning and PostgreSQL connection management. On a VPS, you control the full stack: OpenJDK 21 LTS with Virtual Threads, Maven for builds, Nginx at the front, and PostgreSQL 16 for data. You decide on JVM flags, connection pool size, and deployment strategy. For a production Spring Boot application, this transparency is decisive: you can profile a slow endpoint, adjust -Xmx per service, and deploy a new version with no hidden extra cost.

Concrete Benefits of a Self-Hosted Spring Boot

  • Full control over PostgreSQL: indexes, VACUUM, connection pools, and scheduled pg_dump backups.
  • Virtual Threads (OpenJDK 21 Loom) for Spring WebMVC: hundreds of concurrent requests without reactive rewrites.
  • Fixed, predictable cost regardless of traffic or API request volume.
  • Data and logs under your jurisdiction, useful for compliance and auditing.
  • Freedom of JDK version and system dependencies without buildpack constraints.
  • Reproducible deployments: one fat JAR, one java -jar, and the application is live.

Hardware and Software Requirements

For a Spring Boot application with PostgreSQL, plan at least 2 vCPU and 2 GB RAM; target 4 GB if you run multiple services or a loaded connection pool. The recommended OS is Ubuntu 24.04 LTS — OpenJDK 21 is in the official repositories, no PPA required. A domain name is optional: without one, an SSH tunnel to port 8080 suffices for development and testing. Allocate at least 10 GB of disk for the JVM, application, database, and logs.

Deploy Spring Boot Step by Step

  1. Install OpenJDK 21 and PostgreSQL

    SSH into your VPS and run apt-get install -y openjdk-21-jdk maven nginx postgresql postgresql-contrib — no extra repository setup on Ubuntu 24.04. ⚠️ Name openjdk-21-jdk explicitly: the maven package only depends on default-jre-headless, that is openjdk-21-jre-headless, a runtime with no javac. This is why java -version does print 21.x and makes everything look ready, while the first build on the server fails with No compiler is provided in this environment. Verify: javac -version, mvn -version and psql --version (16.x).

  2. Create the PostgreSQL Database and User

    Connect as sudo -u postgres psql and run CREATE USER myapp WITH PASSWORD 'StrongPassword'; CREATE DATABASE myappdb OWNER myapp;. Set spring.datasource.url=jdbc:postgresql://localhost/myappdb in your application.properties.

  3. Build and Upload the JAR

    Run mvn clean package -DskipTests locally, then transfer the fat JAR to /var/www/your-app/app.jar via scp. Create an application.properties with your PostgreSQL credentials and server.port=8080.

  4. Create a systemd Service

    Create /etc/systemd/system/your-app.service with ExecStart=/usr/bin/java -jar /var/www/your-app/app.jar, Restart=always, User=www-data. Run systemctl daemon-reload && systemctl enable --now your-app. Check with systemctl status your-app and journalctl -u your-app -f.

  5. Configure Nginx and Enable HTTPS

    Create an Nginx server block with proxy_pass http://127.0.0.1:8080; and X-Forwarded-Proto headers. Run certbot --nginx -d your-domain.com for a free Let's Encrypt certificate. Spring Boot listens on the internal port only; Nginx handles TLS.

Use Java 21 Virtual Threads with Spring MVC to multiply throughput without switching to WebFlux: add spring.threads.virtual.enabled=true to your application.properties. Each HTTP request runs in a lightweight virtual thread — thousands can be active simultaneously without saturating the system thread pool. ⚠️ The gain stays conditional on OpenJDK 21: a virtual thread that blocks inside a synchronized block pins its carrier thread instead of releasing it, and that limit is only lifted by JEP 491, in JDK 24. So before expecting a gain on I/O-bound workloads (SQL calls, REST) on a 2 GB VPS, check that your JDBC driver has moved to ReentrantLock — the PostgreSQL one did so starting with 42.6.0 — and measure pinning with the jdk.VirtualThreadPinned JFR event instead of assuming it.

Deploy Spring Boot in One Click from the ServOrbit Marketplace

The ServOrbit Marketplace offers a preconfigured Spring Boot Stack template: OpenJDK 21 LTS, Maven, Nginx, and PostgreSQL 16 are installed automatically on your VPS at order time. No SSH session for the base setup — you arrive directly at the step of uploading your JAR. The marketplace listing contains exact specifications, use cases, and a first-configuration guide.

Deploy Your Spring Boot Stack in Minutes

The ServOrbit Spring Boot Stack template installs OpenJDK 21 LTS, Maven, Nginx, and PostgreSQL 16 on your VPS. Upload your JAR and start immediately.

Need help?

Browse our help center and FAQ, or reach our team — callback, WhatsApp or email. Support in French, English and Arabic.

Message us on WhatsAppopens in a new tab