Deploy HTMX+Spring+Thymeleaf+Postgres
HTMX + Spring + Thymeleaf + Postgres. Full-stack server-rendered app.
Just deployed
Just deployed
/var/lib/postgresql/data
Deploy and Host HTMX+Java+Spring+Thymeleaf+Postgres on Railway
HTMX+Java+Spring+Thymeleaf+Postgres is a starter for hypermedia-driven UIs: Spring Web returns HTML, Thymeleaf renders templates and fragments for HTMX swaps, and PostgreSQL persists data through Spring Data JPA—no SPA and no Node frontend build. Flyway runs SQL migrations, Tailwind + HTMX load from a CDN, and a Todo demo shows partial updates end-to-end.
About Hosting HTMX+Java+Spring+Thymeleaf+Postgres
You deploy a multi-stage Dockerfile (Maven build, slim JRE runtime) that produces a single JAR. The app listens on 0.0.0.0:${PORT:-8080}, reads DATABASE_URL, and RailwayDataSourceConfig maps postgres:// / postgresql:// into HikariCP (with SSL behavior suited to Railway). Flyway applies migrations such as the todos table on startup. GET /health returns JSON and exercises the database for platform checks. Add the Postgres plugin, attach a web service from this repo, and set DATABASE_URL="${{Postgres.DATABASE_URL}}" on the web service (match the DB service name). Git-connected services rebuild on push; app-to-database traffic uses Railway’s private network.
Common Use Cases
- Internal tools and CRUD dashboards where server-rendered HTML and HTMX replace a heavy JavaScript SPA.
- Teams already on Spring who want progressive enhancement and fast iteration with Thymeleaf partials.
- Reference implementations for DATABASE_URL on Railway, Flyway, and HTMX forms and swaps in Java.
Dependencies for HTMX+Java+Spring+Thymeleaf+Postgres Hosting
- A PostgreSQL instance and a valid
DATABASE_URLat runtime (postgres://orpostgresql://). - A web service using this repo’s Dockerfile (Java 21 + Maven in the build stage).
Deployment Dependencies
Implementation Details
- Wire the database:
DATABASE_URL="${{Postgres.DATABASE_URL}}"on the web service (renamePostgresif your plugin service differs). - Health check path: use
GET /health(no trailing slash required for this app). - Templates: Thymeleaf fragments (e.g.
fragments/todo-item.html) pair withhx-swap/hx-targetfor list updates without a full reload.
Why Deploy HTMX+Java+Spring+Thymeleaf+Postgres on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying HTMX+Java+Spring+Thymeleaf+Postgres on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Template Content
PGDATA
data directory (volume); often set by the image
PGPORT
omit for default 5432, or set explicitly
POSTGRES_DB
DB created on first init (official image / plugin)
POSTGRES_USER
superuser name on first init
SSL_CERT_DAYS
optional TLS cert lifetime if you generate certs
RAILWAY_DEPLOYMENT_DRAINING_SECONDS
drain window during deploys