Spring Boot应用部署至IBM WebSphere 8.5.5.21启动失败求助
问题
将基于Java 8、集成Spring Data JPA的Spring Boot 2.7.7应用部署到IBM WebSphere 8.5.5.21服务器时启动失败,本地运行正常,抛出javax.servlet.http.HttpSessionIdListener类未找到错误,详细信息如下:
错误栈
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. [2/3/23 13:29:39:601 IST] 00000146 SystemOut O 2023-03-02 13:29:39.600 ERROR 867310 --- [ebContainer : 0] o.s.boot.SpringApplication : Application run failed org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoClassDefFoundError: javax.servlet.http.HttpSessionIdListener at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.7.7.jar:2.7.7] ...(省略部分栈信息) Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpSessionIdListener at java.net.URLClassLoader.findClass(URLClassLoader.java:610) ~[na:1.8.0] ...(省略部分栈信息)
pom.xml核心配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.7.7</version> <relativePath /> <!-- lookup parent from repository --> </parent> ...(省略部分pom内容) </project>
主类代码
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling public class BsibschedulersApplication extends SpringBootServletInitializer { public static void main(String[] args) { System.out.println("BsibschedulersApplication Started"); SpringApplication.run(BsibschedulersApplication.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { System.out.println("BsibschedulersApplication Configure"); return application.sources(BsibschedulersApplication.class); } }
原因分析
- Servlet API版本不兼容:IBM WebSphere 8.5.5.21仅支持Servlet 3.0规范,而
HttpSessionIdListener是Servlet 3.1才新增的接口。Spring Boot 2.7.7默认依赖Servlet API 4.0版本,导致WebSphere提供的运行环境中不存在该类。 - 依赖打包冲突:若pom.xml未将Servlet API设置为
provided范围,高版本Servlet API会被打包进war包,与WebSphere自带的低版本API发生类加载冲突,加剧异常。
解决方案
- 调整Servlet API依赖配置
在pom.xml中排除Spring Boot自带的高版本Servlet API,显式引入Servlet 3.0版本并设置为provided(由WebSphere提供该依赖):
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency>
- 添加Spring Boot兼容配置
在application.properties中配置WebSphere兼容项:
# 禁用Spring Boot自带的嵌入式Servlet容器 spring.main.web-application-type=none # 设置应用上下文路径 server.servlet.context-path=/your-app-context
- 修改WebSphere类加载模式
在WebSphere控制台调整应用类加载策略为PARENT_LAST:
- 进入应用管理页面,找到目标应用
- 点击「类加载和更新检测」选项
- 将类加载顺序设置为「PARENT_LAST」,保存后重启应用
内容的提问来源于stack exchange,提问作者Sakthi Prasad S
相关产品推荐
相关产品推荐

