Kotlin+Spring Cloud Netflix启动Eureka服务器遇连接拒绝异常的解决方法
问题解决:Eureka服务器启动时出现连接拒绝异常
核心问题分析
从日志中可以定位到两个关键问题:
- Spring Cloud Config自动触发无效配置拉取:程序启动时默认尝试连接
http://localhost:8888(Spring Cloud Config Server默认端口),但你并未部署该服务,这会导致配置加载警告,同时可能干扰本地配置的优先级。 - Eureka服务器实际启动端口与配置不符:日志明确显示
Tomcat initialized with port(s): 8080 (http),但你在配置文件中指定的是server.port=8761,配置未生效导致Eureka客户端尝试连接8761端口时被拒绝。
具体修复步骤
1. 移除不必要的依赖
你的Eureka Server项目无需Spring Cloud Config相关依赖,直接从pom.xml中删除以下内容:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency>
2. 确保配置文件生效
如果移除依赖后端口仍未生效,检查以下几点:
- 确认
application.properties放置在src/main/resources目录下,路径无误。 - 若存在
bootstrap.properties/yml文件,检查其中是否有冲突的server.port配置(bootstrap配置优先级高于application)。 - 可将
application.properties改为application.yml,降低语法出错概率:
server: port: 8761 spring: application: name: eureka-server eureka: instance: hostname: localhost server: maxThreadsForPeerReplication: 0 client: register-with-eureka: false fetch-registry: false
3. 验证修复结果
启动项目后,查看日志确认Tomcat启动端口为8761:
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8761 (http)
访问http://localhost:8761即可看到Eureka管理页面,连接拒绝异常将不再出现。
内容的提问来源于stack exchange,提问作者John Adams
相关产品推荐
相关产品推荐

