You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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:
    ps aux | grep java
    
    If you don't see your Spring Boot app listed, go back to the startup logs and look for error messages (like Port 8080 is already in use or 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=8081 to your application.properties file, restart the app, then try curl localhost:8081/api instead.

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 added server.servlet.context-path=/myapp to application.properties, your API URL would be localhost: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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:21:32