Deploy Spring Boot 3 on Render in 10 Minutes — package JAR, connect PostgreSQL, set env vars

Deploy Spring Boot 3 on Render in 10 Minutes

Package your JAR, connect PostgreSQL, set env variables, and push to production the simple way.

Why Render for Spring Boot?

Render is a developer-friendly PaaS that builds your app on every push, gives you a public URL, and offers a free tier for testing. You can add a managed PostgreSQL in a couple of clicks, and keep secrets as environment variables for clean, repeatable deploys.

What you’ll build (in ~10 minutes)

  • Package a Spring Boot 3 app as an executable JAR (Maven or Gradle)
  • Create a managed PostgreSQL on Render
  • Configure environment variables (including the port Render expects)
  • Deploy with build & start commands and verify it’s live

Prereqs: Java 17+, a Spring Boot 3 project in GitHub/GitLab/Bitbucket, and a free Render account.

0) Prepare your app (1 minute)

Spring Boot already produces executable archives. With the Boot Maven/Gradle plugin, your JAR will run via java -jar. Nothing exotic required.

Add a tiny safety line so your app binds to the port Render assigns:

src/main/resources/application.properties

# Use the port provided by Render (defaults to 10000 there). Locally falls back to 8080.
server.port=${PORT:8080}

Render sets/accepts a PORT env variable; the default expected port is 10000.

1) Build your JAR (Maven or Gradle) (2 minutes)

Maven (recommended):

# uses the Spring Boot Maven Plugin to build an executable jar
./mvnw -DskipTests clean package
# JAR ends up in target/*.jar

The Boot Maven Plugin “repackages” dependencies into an executable JAR that runs with java -jar.

Gradle:

# creates an executable boot jar
./gradlew bootJar
# JAR ends up in build/libs/*.jar

bootJar is the Spring Boot Gradle task that builds an executable JAR.

2) Create a managed PostgreSQL on Render (2 minutes)

  1. In the Render dashboard, click New → Postgres and create a database.
  2. After it’s Available, open Connect to see both internal (for same-region Render services) and external URLs. Prefer the internal URL from your Spring app for lower latency.

The connection URLs look like postgresql://USER:PASSWORD@HOST:5432/DBNAME. You can copy individual values (host, user, etc.) from the DB Info page too.

3) Configure Spring Boot to read env vars (2 minutes)

Spring Boot supports externalized configuration out of the box: you can set properties with environment variables like SPRING_DATASOURCE_URL, SPRING_DATASOURCE_USERNAME, and SPRING_DATASOURCE_PASSWORD.

On Render, add these env vars to your Web Service (we’ll create it in step 4, but you can prep the list now):

  • SPRING_DATASOURCE_URL = jdbc:postgresql://<HOST>:5432/<DBNAME>?sslmode=require
  • SPRING_DATASOURCE_USERNAME = <USER>
  • SPRING_DATASOURCE_PASSWORD = <PASSWORD>
  • (optional) SPRING_JPA_HIBERNATE_DDL_AUTO = update (or your migration strategy)

Why JDBC? Spring’s Postgres driver expects a JDBC URL (jdbc:postgresql://...). If you copied Render’s standard Postgres URL, convert it to JDBC form and pass username/password separately (or as query params).

To add env vars in Render: open your service → EnvironmentAdd Environment Variable.

Tip: You don’t have to reference these in application.properties—Spring automatically maps SPRING_DATASOURCE_URLspring.datasource.url (relaxed binding).

4) Create a Render Web Service and wire it up (3 minutes)

  1. In Render, click New → Web Service, connect your repo, choose your branch.
  2. Runtime: use a native runtime (Java) or “Other” (we’ll rely on commands). Render will build on each push and give you a live URL.
  3. Build Command (pick one):
    • Maven: ./mvnw -DskipTests clean package
    • Gradle: ./gradlew bootJar
  4. Start Command (point to your built JAR):
    • Maven layout: java -jar target/<your-app>.jar
    • Gradle layout: java -jar build/libs/<your-app>.jar
      This is the standard way to run an executable Spring Boot JAR.
  5. Environment (service → Environment): add the DB and any app vars from step 3. Also ensure Render’s PORT is honored (we did that in step 0).

After the first deploy, Render gives you an onrender.com URL and marks the service Live when it’s healthy.

5) Test it live (1 minute)

Open your Render URL (e.g., https://yourapp.onrender.com) and hit any health or REST endpoint. You can also find the external URL in the RENDER_EXTERNAL_URL env var at runtime.

Optional goodies

  • Free tier caveat: Great for demos & testing; don’t rely on it for production SLAs.
  • Static outbound IPs: If your app must call IP-restricted services, Render exposes a fixed list per service.
  • Port rules recap: Web services must bind on 0.0.0.0 to the provided PORT (default 10000). We handled this with server.port=${PORT:8080}.

Minimal application.properties

# Match Render’s port at runtime, default to 8080 locally
server.port=${PORT:8080}

# JPA/Hibernate (use Flyway/Liquibase for real migrations)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.open-in-view=false

# Let env vars drive the datasource on Render
# These map automatically from SPRING_DATASOURCE_* env vars
# (No hardcoded secrets in your repo)

Spring uses environment variables to override properties cleanly at startup.

Troubleshooting (quick fixes)

  • “Refused to connect” or 404 on your URL
    Make sure your app binds to the Render port (server.port=${PORT:8080}) and is listening on 0.0.0.0.
  • DB connection errors
    Use the internal DB URL when your app is on Render (same region), convert to JDBC form, and set user/password via env vars. Verify sslmode=require if your driver expects TLS.
  • Start command fails
    Ensure the path to your JAR matches your build tool’s output (target/... for Maven, build/libs/... for Gradle) and use java -jar.

Final checklist

  • server.port=${PORT:8080} added
  • JAR builds locally (mvn package or gradlew bootJar) Home+1
  • Postgres created on Render; copied connection details Render
  • Env vars set on the Web Service (datasource URL/username/password) Render
  • Build/Start commands configured; deploy shows Live Render

References & further reading

  • Render — Web Services (builds on push, port rules, URLs): Here
  • Render — Default & Optional Environment Variables (incl. PORT): Here
  • Render — Create & Connect to Postgres (internal vs external URL, connection formats): Here
  • Spring Boot — Executable JARs: Here
  • Spring Boot — Externalized Configuration (env variables → properties): Here
  • PostgreSQL JDBC — Connection Basics (JDBC URL shape): Here
  • Render — Env Vars & Secrets (where to add them): Here
  • Render — Start command for JAR (community note, standard java -jar): Here

Wrap-up

With a couple of small conventions—executable JAR, JDBC URL, and the PORT env var—you can take a Spring Boot 3 app live on Render in minutes and keep your configuration clean for future automation.

Leave a Comment

Your email address will not be published. Required fields are marked *