Mac环境下构建Spring Boot项目调用API遇curl连接拒绝问题求助
Troubleshooting "Connection refused" when calling Spring Boot API on Mac
Hey there, let's work through why you're hitting that Failed to connect to localhost port 8080: Connection refused error after setting up your Spring Boot + React project. I've dealt with this exact issue a few times, so here are the most common fixes to check step by step:
1. Verify your Spring Boot application is actually running
- First, check the terminal window where you started the app. Did it crash immediately with an error? Common culprits here include missing dependencies, invalid configuration, or a port conflict.
- To confirm if a Java process is active, run this command in a new terminal:
If you don't see your Spring Boot app listed, go back to the startup logs and look for error messages (likeps aux | grep javaPort 8080 is already in useor missing bean definitions).
2. Check if port 8080 is occupied by another process
- Port 8080 is a popular default, so it might be used by another service (like Apache, nginx, or another Java app). To find out which process is using it:
lsof -i :8080 - If you see a process listed, you can either kill it with
kill -9 <PID>(replace<PID>with the process ID from the output) or change your Spring Boot port:- Add
server.port=8081to yourapplication.propertiesfile, restart the app, then trycurl localhost:8081/apiinstead.
- Add
3. Confirm your API endpoint and context path are correct
- Double-check if the tutorial's API endpoint is indeed
/api. Did you accidentally set a custom context path in your app? If you addedserver.servlet.context-path=/myapptoapplication.properties, your API URL would belocalhost:8080/myapp/api. - Look for lines like
Mapped "{/api/**}"in your startup logs—this confirms the endpoint is properly registered.
4. Rule out firewall or proxy interference
- Mac's built-in firewall rarely blocks localhost requests, but it's worth temporarily disabling it (System Preferences > Security & Privacy > Firewall) to test.
- If you're using a proxy tool (like Charles, Fiddler, or browser extensions), it might be redirecting your localhost request. Try disabling the proxy and running the curl command again.
5. Double-check your curl command
- It sounds silly, but typos happen! Make sure your command is exactly:
curl localhost:8080/api - You can also test the endpoint in your browser by visiting
http://localhost:8080/api—if the browser also can't connect, the issue is definitely with the app or port, not curl.
If none of these steps work, share the full startup logs from your Spring Boot app, and we can dig deeper into what's going wrong.
内容的提问来源于stack exchange,提问作者Nespony
相关产品推荐
相关产品推荐

