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

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:

1. Ensure your WAR setup is configured for external Tomcat

First, confirm you've adjusted your project properly for WAR deployment:

  • Set the packaging type to war in your pom.xml:
    <packaging>war</packaging>
    
  • Mark the embedded Tomcat dependency as provided to 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 SpringBootServletInitializer and override the configure method—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);
        }
    }
    
2. Resolve the 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
3. Verify compatibility between Tomcat and Spring Boot

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.
4. Rebuild and redeploy

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:30:28