4 months ago
Description:
I'm trying to deploy my Spring Boot 3.3.5 application on Railway, but after every successful deployment, when I access the public URL, I get a 502 Bad Gateway error. Locally, everything works perfectly (Swagger loads, endpoints respond normally), but on Railway, it never passes the health check.
Here's what I've tried so far:
Set my profile to
prdand addedSPRING_PROFILES_ACTIVE=prdin Railway environment variables.Configured
application-prd.ymllike this:
CopiarEditar
server: port: ${PORT:8080} spring: datasource: url: jdbc:postgresql://${PGHOST}:${PGPORT}/${PGDATABASE}?sslmode=require username: ${PGUSER} password: ${PGPASSWORD} jpa: open-in-view: false hibernate: ddl-auto: validate springdoc: swagger-ui: path: /swagger-ui.html api-docs: path: /v3/api-docs
Added a simple health controller:
CopiarEditar
@RestController public class HealthController { @GetMapping("/") public String home() { return "Application online!"; } }
Confirmed that PostgreSQL is reachable, tables already exist, and Hibernate connects successfully (
HikariPool-1 - Start completedappears in logs).Tested locally with
PORT=9090andSPRING_PROFILES_ACTIVE=prd→ works fine on that port.
However, on Railway:
The logs show the app starting fine on port 8080.
GET
/returns status 499 or 502.Railway dashboard keeps showing Port 8080, as if the
${PORT}variable is not being picked up by Spring Boot.
I’ve already forced redeploys (clean builds, rebuild from scratch) and the same issue persists.
Railway error reference:Application failed to respond
Support code:Zg5wU9DHRS-qSmA0g4a9AQ
Question:
Why is my Spring Boot app ignoring the
${PORT}environment variable on Railway?How can I make Railway recognize my app and stop returning 502 even though deploy logs show no errors?
4 Replies
4 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
Railway
Hey there! We've found the following might help you get unblocked faster: - [🧵 502 Bad Gateway](https://station.railway.com/questions/502-bad-gateway-475c90b4) - [🧵 502 Bad Gateway Error](https://station.railway.com/questions/502-bad-gateway-error-aca2311e) - [🧵 502 Bad Gateway](https://station.railway.com/questions/502-bad-gateway-2c8d2e43) If you find the answer from one of these, please let us know by solving the thread!
4 months ago
I still need help with this issue.
Even after trying all the suggested fixes, my Spring Boot application on Railway still returns 502 Bad Gateway.
Support code: Zg5wU9DHRS-qSmA0g4a9AQ
Could someone from the team or community please help me figure out why the application ignores the ${PORT} variable and fails the health check, even though logs show it starts successfully?
andressasmedeiros
I still need help with this issue.Even after trying all the suggested fixes, my Spring Boot application on Railway still returns 502 Bad Gateway.Support code: Zg5wU9DHRS-qSmA0g4a9AQCould someone from the team or community please help me figure out why the application ignores the ${PORT} variable and fails the health check, even though logs show it starts successfully?
4 months ago
You can check my post on healthcheckups, andressasmedeiros: https://station.railway.com/questions/node-js-service-failing-to-deploy-with-s-dc58e402#mk2w
If that does not help, please provide the health endpoint that you have configured, along with the intial configuration lines for your server (in which you have defined & used the PORT thing)
clashing
You can check my post on healthcheckups, andressasmedeiros: https://station.railway.com/questions/node-js-service-failing-to-deploy-with-s-dc58e402#mk2wIf that does not help, please provide the health endpoint that you have configured, along with the intial configuration lines for your server (in which you have defined & used the PORT thing)
4 months ago
andressasmedeiros. any update!
If my post helped, do mark that as the solution