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

自定义spring-boot-starter未加载致Spring Boot应用启动失败

问题排查与解决方案

1. 检查自定义Starter的自动配置适配情况

Spring Boot 3.x 不再使用 META-INF/spring.factories 加载自动配置类,改用 META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports 文件。如果你的自定义 starter 基于 Spring Boot 2.x 开发,需做以下调整:

  • 在 starter 的 src/main/resources/META-INF/spring 目录下创建上述文件,将自动配置类的全限定名逐行写入
  • 确认自动配置类上的条件注解(如 @ConditionalOnClass、@ConditionalOnProperty)在 Spring Boot 3.x 下仍有效,比如检查类路径中是否存在注解指定的类

2. 验证Gradle依赖引入的正确性

  • 确认依赖坐标无拼写错误,示例如下:
    implementation 'ru.quipy:tiny-event-sourcing-spring-boot-starter:xxx'
    implementation 'ru.quipy:tiny-mongo-event-store-spring-boot-starter:xxx'
    
  • 执行 ./gradlew dependencies 命令,检查依赖树中是否包含 EventSourcingServiceFactory 所在的 jar 包,同时排查是否存在依赖冲突(如 Spring 核心依赖版本不一致)

3. 检查配置属性的兼容性

Spring Boot 3.x 对配置属性做了部分调整,包括前缀变更、属性类型约束更严格:

  • 对比 Spring Boot 2.7.7 和 3.2.0 中使用的配置属性,确保 application.yml/application.properties 中的属性前缀、名称完全匹配 starter 要求
  • 排查是否因属性类型不兼容(如数值、布尔类型格式变化)导致自动配置类跳过初始化

4. 排查配置类的Bean加载时机

  • 确保自定义的 EventSourcingConfig 类添加了 @Configuration 注解,且被 Spring 组件扫描覆盖(比如所在包在 @SpringBootApplication 的扫描范围内,或手动通过 @ComponentScan 指定)
  • 如果 EventSourcingServiceFactory 初始化依赖其他 Bean,可在注入时添加 @Lazy 注解延迟加载,避免初始化顺序或循环依赖问题:
    @Autowired
    @Lazy
    private EventSourcingServiceFactory eventSourcingServiceFactory;
    

5. 检查依赖版本冲突

Spring Boot 3.x 依赖 Spring 6.x 和 Jakarta EE 9+,而 Spring Boot 2.7.x 依赖 Spring 5.x 和 Java EE:

  • 确认自定义 starter 中的依赖(如 MongoDB 驱动、Spring 相关依赖)适配 Jakarta EE 规范,避免因类路径中同时存在 javax.* 和 jakarta.* 类导致 Bean 无法创建
  • 使用 Gradle 的 dependencyInsight 命令排查特定依赖的版本:
    ./gradlew dependencyInsight --dependency org.springframework:spring-core
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 21:27:21