Spring Boot打包WAR部署外部Tomcat遇javax.el缺失问题求助
Hey there, let's figure out why your Spring Boot WAR is throwing that javax.el not found error when deploying to external Tomcat, even though it works fine in STS. I've dealt with this exact issue before, so here's what you need to check and fix:
First, confirm you've adjusted your project properly for WAR deployment:
- Set the packaging type to
warin yourpom.xml:<packaging>war</packaging> - Mark the embedded Tomcat dependency as
providedto avoid conflicts with the external Tomcat instance (this prevents bundling the embedded server into your WAR):<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> - Update your main application class to extend
SpringBootServletInitializerand override theconfiguremethod—this tells external Tomcat how to bootstrap your Spring Boot application:@SpringBootApplication public class YourAppApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(YourAppApplication.class); } public static void main(String[] args) { SpringApplication.run(YourAppApplication.class, args); } }
javax.el dependency gap The error occurs because components like Hibernate/JPA or HikariCP (which use EL expressions for configuration) require the EL API, but external Tomcat's classloader doesn't expose it properly to your web app. Fix this by adding explicit EL dependencies:
Add these to your pom.xml, setting their scope to provided (since Tomcat already includes these libraries, we just need to ensure your app can access them):
<dependency> <groupId>javax.el</groupId> <artifactId>javax.el-api</artifactId> <version>3.0.1-b06</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.el</artifactId> <version>3.0.1-b06</version> <scope>provided</scope> </dependency>
Choose a version matching your Tomcat:
- Tomcat 8.5+ uses EL 3.0 (the version above works)
- Tomcat 7 requires EL 2.2, e.g.,
2.2.1-b05
Make sure your Tomcat version is supported by your Spring Boot version:
- Spring Boot 2.0+ → Tomcat 8.5+ or 9.x
- Spring Boot 1.5 → Tomcat 7, 8, or 8.5
Incompatible versions often cause classpath-related issues like this.
After making these changes, run your Maven build again (skip tests as you did before):
mvn clean package -DskipTests
Then redeploy the new WAR file to Tomcat and restart the server.
That should fix the javax.el not found error. Let me know if you run into any other issues!
内容的提问来源于stack exchange,提问作者oneslide icywater

