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

Spring Boot 1.3.8中@Bean方法在Ubuntu 22下不生效的问题排查

Spring Boot 1.3.8跨系统@Bean方法不执行问题排查

问题背景

我们维护一个基于Spring Boot 1.3.8的旧项目,包含如下@Configuration类:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.smartinnotec.aposoft.email.type.EmailMessage;
import com.smartinnotec.aposoft.email.type.GeneralEmailInformationMessage;

import lombok.Data;

//if this class has name GeneralEmailConfiguration with Win 10 
//than @Bean does not work, therefore Schedule...
@Configuration
public @Data class ScheduleGeneralEmailConfiguration {

    protected EmailMessage generalMessage;

    public ScheduleGeneralEmailConfiguration() {
        System.out.println("ScheduleGeneralEmailConfiguration");
    }

    @Bean
    public EmailMessage generalEmailMessage() {
        this.generalMessage = new GeneralEmailInformationMessage();
        return generalMessage;
        }
    }

异常现象

该类中的@Bean方法generalEmailMessage()在Windows 10系统下能正常被调用,但切换到Ubuntu 22系统后,完全相同的应用中该方法不再执行。

临时解决方法

将方法重命名为如下形式后,@Bean方法恢复正常:

@Bean
public EmailMessage generalEmailInformationMessage() {
    this.generalMessage = new GeneralEmailInformationMessage();
    return generalMessage;
}

排查方向与解决方案

  • 大小写敏感问题:Ubuntu是大小写敏感系统,Windows则不是。检查GeneralEmailInformationMessage类的文件名是否和类名完全一致;排查项目中是否存在大小写不同的同名@Bean方法或类,这类情况在Windows下会被合并,但Linux下会触发Bean注册冲突。
  • Spring Boot旧版本Bug:Spring Boot 1.3.8是2016年的老旧版本,存在已修复的Bean注册逻辑Bug,在大小写敏感的文件系统下可能出现匹配异常。建议升级到1.3.x分支的最新补丁版(如1.3.9.RELEASE),或尝试兼容旧代码的1.5.x稳定版。
  • Lombok兼容性问题:项目使用的Lombok版本可能与Spring Boot 1.3.8不兼容,不同系统下字节码生成逻辑有差异。建议更换为与Spring Boot 1.3.x匹配的Lombok版本(如1.16.18),或临时去掉@Data注解手动生成getter/setter,验证是否是Lombok导致的问题。
  • 类路径与日志排查:检查打包后的文件是否包含目标配置类;开启Spring的DEBUG日志(设置logging.level.org.springframework=DEBUG),对比Windows和Ubuntu下的Bean注册日志,定位未注册的具体原因。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 03:05:05