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

Eclipse中Maven项目端口连接被拒绝,如何配置修复该错误?

解决Eclipse中java.net.ConnectException: Connection refused的配置方案

Hey there, let's figure out how to fix that java.net.ConnectException: Connection refused error you're seeing in Eclipse. This error almost always means your application is trying to reach a server that's either not running, using the wrong port, or being blocked by network settings. Here's a step-by-step guide to troubleshoot and configure Eclipse correctly:

1. 先确认目标服务是否正常运行

  • First things first: make sure the server you're trying to connect to (like Tomcat, MySQL, or a custom Java service) is actually up and running. For local services, check its console for startup errors. You can also verify if the port is being listened on using command line tools:
    • Windows: netstat -ano | findstr :<你的端口号>
    • Mac/Linux: lsof -i :<你的端口号> or netstat -tulpn | grep <你的端口号>
  • If it's a remote server, test basic connectivity first with ping <主机地址>, then check if the port is open using telnet <主机地址> <端口> or nc -zv <主机地址> <端口>.

2. 检查项目中的连接配置细节

  • Open your Eclipse project and locate your configuration files (like application.properties, hibernate.cfg.xml, or a custom config class). Double-check that the host address and port number match exactly with the target server's settings. For example:
    • If you're connecting to a local MySQL instance, did you use localhost/127.0.0.1 and the default port 3306 (not a typo like 3307)?
  • For web projects using a server like Tomcat: Right-click your project → Run As → Run Configurations → Select your server instance. Verify its HTTP/AJP ports match what your code is trying to access.

3. 调整Eclipse的网络代理设置

  • Sometimes Eclipse's proxy configuration can block connections (even local ones!). Go to Window → Preferences → General → Network Connections.
  • Set the Active Provider to Direct if you don't need a proxy. If you do use a proxy, make sure the proxy address/port is correct, and add exceptions for local addresses like localhost, 127.0.0.1 to the proxy bypass list.

4. 排查防火墙或安全软件干扰

  • Local firewalls or antivirus tools might be blocking your Java application from establishing connections. Try temporarily disabling them to see if the error goes away. If it does, add Eclipse or your Java executable to the firewall's allowed applications list.
  • For remote servers, confirm the server-side firewall has opened the port you're trying to connect to.

5. 清理项目缓存并重新构建

  • Eclipse's cached build files can sometimes cause outdated configurations to stick. Go to Project → Clean..., select your project, and click Clean.
  • If you're using Maven, right-click the project → Maven → Update Project (check "Force Update of Snapshots/Releases" if needed) to refresh dependencies and configurations.

6. 调试确认连接参数

  • Add a quick log statement or breakpoint in your code to verify the exact host and port your app is trying to connect to. For example:
String host = "localhost";
int port = 3306;
System.out.println("Attempting connection to: " + host + ":" + port);
  • Run your project in Debug mode, pause at the connection code, and confirm these parameters are correct—typos here are way more common than you think!

内容的提问来源于stack exchange,提问作者D.Joyce

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 08:27:26