Railway

Deploy HTMX+Spring+Thymeleaf+MySQL

HTMX + Spring + Thymeleaf + MySQL. Full-stack server-rendered app.

Deploy HTMX+Spring+Thymeleaf+MySQL

Just deployed

/var/lib/mysql

Deploy and Host HTMX+Spring+Thymeleaf+MySQL on Railway

HTMX + Spring Boot + Thymeleaf + MySQL is a server-rendered full-stack setup: Spring Boot serves HTML with Thymeleaf, HTMX updates fragments without a heavy SPA, and MySQL stores data through JPA. You ship one JVM service in Docker; Flyway runs SQL migrations at startup. Tailwind and HTMX load from a CDN, so there is no separate frontend build pipeline.

About Hosting HTMX+Spring+Thymeleaf+MySQL on Railway

Hosting means running a multi-stage Dockerfile (Maven build, slim JRE runtime) as a web service and adding Railway’s MySQL plugin. The app expects DATABASE_URL as a mysql://user:pass@host:3306/database string; on Railway, set DATABASE_URL="${{MySQL.MYSQL_URL}}" on the web service so it uses the plugin’s private-network URL. RailwayDataSourceConfig parses that URL into a HikariCP jdbc:mysql:// datasource and enables SSL for non-local hosts. Flyway applies migrations (for example V1__todos.sql) before the app accepts traffic. Configure the service health check to GET /health, which returns JSON and verifies the database. PORT defaults to 8080. Thymeleaf templates and HTMX attributes live in the repo; no Node bundler is required for the demo UI.

Common Use Cases

  • Internal tools and ops dashboards — partial page updates with hx-post / hx-patch / hx-delete without maintaining a separate API + SPA.
  • CRUD and form-heavy apps — server validation and SSR-friendly flows while keeping the stack on Java and MySQL.
  • MVPs and teaching stacks — one repo, one container, familiar Spring + SQL, easy to extend with Spring Security or more domains later.

Dependencies for HTMX+Spring+Thymeleaf+MySQL Hosting

  • Railway MySQL (or any MySQL-compatible mysql:// URL exposed as DATABASE_URL).
  • Web service built from this template’s Dockerfile at the repository root.

Deployment Dependencies

Implementation Details

  • On the web service: DATABASE_URL="${{MySQL.MYSQL_URL}}" (must start with mysql://).
  • Health check path: /health.
  • Example local run: export DATABASE_URL="mysql://user:pass@127.0.0.1:3306/db" then mvn spring-boot:run.
  • Thymeleaf fragments under templates/fragments/ are swapped by HTMX for the included todo demo.

Why Deploy HTMX+Spring+Thymeleaf+MySQL 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+Spring+Thymeleaf+MySQL 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

More templates in this category

View Template
caring-vibrancy
Deploy and Host caring-vibrancy with Railway

baleocho
View Template
Flask WebSocket Chat
Single file, realtime multi-user websocket chat using flask-socketio

Clement Ochieng
View Template
all-star-fashion-template
Deploy and Host all-star-fashion-template with Railway

Mai Thành Duy An