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

Spring Boot Eureka Server启动失败:找不到ServerProperties Bean的解决方法

问题原因及解决方法

原因分析

  1. 打包方式与主类配置不兼容:项目设置为war打包模式,但主类未继承SpringBootServletInitializer,导致Spring Boot的Web核心自动配置类(包括ServerProperties)无法被正确初始化加载。
  2. 冗余的依赖版本指定:在已通过dependencyManagement导入Spring Cloud全局依赖管理的情况下,手动指定spring-cloud-starter-netflix-eureka-server的版本,可能引发依赖版本冲突,干扰自动配置Bean的创建流程。

解决方法

方法一:切换为Jar打包(推荐)

Eureka Server作为独立运行的注册中心,使用Jar打包是更合适的选择,无需额外Servlet适配:

  1. 修改pom.xml中的打包类型:
<packaging>jar</packaging>
  1. 保持现有主类代码不变,执行mvn clean install后重新启动项目。

方法二:适配War打包的主类

若必须使用War打包,需调整主类继承SpringBootServletInitializer以支持Web容器部署:

@SpringBootApplication
@EnableEurekaServer
public class DiscoveryServerApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(DiscoveryServerApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DiscoveryServerApplication.class);
    }
}

方法三:移除冗余依赖版本指定

删除spring-cloud-starter-netflix-eureka-server的手动版本声明,让Spring Cloud的依赖管理自动匹配兼容版本:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    <!-- 移除该行手动版本指定 -->
    <!-- <version>4.0.2</version> -->
</dependency>

执行上述调整后,重新构建并启动项目,ServerProperties Bean将被正常加载,Eureka Server即可启动成功。

内容的提问来源于stack exchange,提问作者Thimira Pathirana

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 11:33:26