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

Spring Native构建的Spring Boot应用启动即退出,Tomcat未运行

问题原因分析

核心错误为 Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context,导致该问题的关键原因有两点:

  1. 不必要的SpringBootServletInitializer继承
    你的应用类继承了SpringBootServletInitializer,这个类仅用于将Spring Boot应用打包为WAR包、部署到外部Servlet容器的场景。而Spring Native构建的是独立可执行文件,依赖内置Servlet容器的自动配置逻辑,继承该类会干扰Spring Boot的自动配置流程,导致负责创建内置Tomcat/Undertow/Jetty的ServletWebServerFactory无法被正确初始化。

  2. Dockerfile中ENTRYPOINT的写法错误
    当前ENTRYPOINT使用数组模式时,将命令与参数合并为单个字符串,这会导致整个字符串被当作独立命令执行,而非将--spring.profiles.active=local作为参数传递给应用程序,可能进一步加剧配置加载异常。

解决方案

1. 修改应用类,移除SpringBootServletInitializer继承

将应用类改为普通Spring Boot启动类,去掉不必要的继承:

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

2. 修复Dockerfile的ENTRYPOINT写法

使用数组模式时,需将命令与每个参数分开声明:

ENTRYPOINT ["./chatbot-member-event-worker", "--spring.profiles.active=local"]

或使用更直观的Shell模式:

ENTRYPOINT ./chatbot-member-event-worker --spring.profiles.active=local

3. 重新构建并启动

执行Docker构建命令重新生成镜像,启动后Spring Boot会自动初始化内置Servlet容器的ServletWebServerFactory Bean,Web服务即可正常启动并持续运行。

内容的提问来源于stack exchange,提问作者Alpcan Yıldız

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 10:45:16