9 days ago
I’m deploying a Spring Boot (Java 21) backend with PostgreSQL on Railway, but the application is failing during startup due to environment variable resolution issues. The backend uses a custom HikariCP DataSourceConfig and Flyway, and it expects PostgreSQL credentials via environment variables (PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD) or Railway reference variables from the Postgres service. Although I have configured both Shared Variables and Reference Variables in Railway, the values are not being resolved correctly at runtime and sometimes appear as null or unresolved placeholders like ${{PostgresDB.PGHOST}}.
Because of this, the application fails with errors such as Driver org.postgresql.Driver claims to not accept jdbcUrl and Failed to initialize JPA EntityManagerFactory, preventing the backend from starting successfully. I need help understanding the correct and reliable way to connect Railway PostgreSQL variables to a Spring Boot backend and why the environment variables are not being injected properly at runtime.
Attachments
1 Replies
Status changed to Open Railway • 9 days ago
9 days ago
you have 12 staged changes that were never applied so your variables exist in the dashboard but the running container never received them that's exactly why the logs say they are missing just click "apply 12 changes" then deploy if it still crashes after that share your datasourceconfig code so i can dig deeper