page:guides:spring boot:database connection
Connect Postgres for Spring Boot
Database connection for a Spring Boot app on Ample. Verified on Spring Boot: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Build and start: ./mvnw -q -DskipTests package (or the Gradle wrapper) producing one application jar, then java -jar on the jvm-21 template (Temurin JDK 21) with server.port read from PORT.
Prerequisites
- A Spring Boot project (
./mvnw -q -DskipTests package (or the Gradle wrapper) producing one application jar, then java -jar on the jvm-21 template (Temurin JDK 21) with server.port read from PORT) - A PostgreSQL driver reading DATABASE_URL at runtime
- An Ample account token with
servers:write,databases:read
Workflow Steps
- Build and start
./mvnw -q -DskipTests package (or the Gradle wrapper) producing one application jar, then java -jar on the jvm-21 template (Temurin JDK 21) with server.port read from PORT; the server must bind 0.0.0.0 on PORT. - Read DATABASE_URL at runtime
Open connections from the environment inside handlers or a pool; omitDATABASE_URLto auto-provision a managed database or pass--env DATABASE_URL=...for an existing one. - Verify
Fetch the live URL and/p/relational-recordson the example; on failure read the build and runtime logs. Command:ample logs --kind build
Examples
- Spring Boot pattern fixture
Verified database connection on Spring Boot.
Source:tests/deploy-canaries/spring-boot-patterns
Success Checks
- app responds on its public URL
Kind:http_get
Path:/
Expect:ample canary spring boot patterns - relational-records check from the example
Kind:http_get
Path:/p/relational-records
Expect:see the pattern fixture checks
Limitations
- Verified on the jvm-21 template at s-1vcpu-2gb; other sizes and Spring Boot major versions are not verified.
- Region, compliance attestations and request-duration limits are unknown and not claimed.
- Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.
Cost Estimate
- Currency: USD
- Monthly Amount: $10.00
- Authoritative: true
- Basis: size prices from pricing.toml (loaded by the API) at build revision 1ac5595375130d45290090e82ed0f554ccd45405-dirty
- Components:
- App server
Size:s-1vcpu-1gb, Quantity: 1.0, Monthly Amount: $5.00 - Managed PostgreSQL database
Size:s-1vcpu-1gb, Quantity: 1.0, Monthly Amount: $5.00
- App server
- Note: Always-on monthly price of the tested sizes; apps auto-pause when idle. Buckets are allocation-priced per quota and not included.
Evidence Summary
- Kind:
canary_run
Summary:Spring Boot pattern fixture deployed on Ample (...); for this guide: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok).
Observed At:2026-09-21T02:34:39Z
Implementation Revision:1d28ae0-dirty (CLI 0.1.21)
Expires At:2027-03-20T02:34:39Z
Scope:- Checks:
/p/relational-records - Template:
jvm-21
- Checks:
Last Verified At
2026-09-21T02:34:39Z
Unknowns
- Region availability is unknown until a verified region fact is recorded.
- Compliance attestations are unknown; none are claimed.