Spring Boot 2 WAR部署Tomcat7时ELManager类缺失问题咨询
Got it, let's work through this step by step. The core issue here is that Spring Boot 2's default Hibernate Validator 6.x requires EL 3.0, but Tomcat 7 only ships with EL 2.2. We need to align your dependencies to match Tomcat 7's environment without triggering classloader conflicts. Here's what to do:
1. Downgrade Hibernate Validator to support EL 2.2
Spring Boot 2 uses Hibernate Validator 6.x out of the box, which depends on EL 3.0. Since Tomcat 7 can't handle that, we need to roll back to Hibernate Validator 5.x (a stable version compatible with EL 2.2). Add this to your build.gradle to override the default version:
ext['hibernate-validator.version'] = '5.4.3.Final'
2. Align Tomcat dependencies to 7.0.76 and fix EL dependencies
You already set ext['tomcat.version'] = '7.0.76'—great start. Now we need to make sure we're using Tomcat 7's native EL libraries and exclude any conflicting embedded Tomcat EL dependencies:
First, confirm your WAR is configured for external Tomcat deployment (not executable) and mark the embedded Tomcat as provided:
plugins { id 'org.springframework.boot' version '2.7.x' // Stick to 2.7.x, it's the last Spring Boot 2 branch supporting Tomcat 7 id 'war' id 'java' } war { enabled = true } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' // Mark embedded Tomcat as provided—we don't want it in our WAR providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' // Exclude the embedded Tomcat EL JAR that comes with starter-web implementation('org.springframework.boot:spring-boot-starter-web') { exclude group: 'org.apache.tomcat.embed', module: 'tomcat-embed-el' } // Add Tomcat 7's official EL API and implementation as provided (Tomcat already has these) providedRuntime 'org.apache.tomcat:tomcat-el-api:7.0.76' providedRuntime 'org.apache.tomcat:tomcat-el-impl:7.0.76' }
3. Verify no conflicting dependencies
Run this Gradle command to check your dependency tree and ensure no EL 3.0 dependencies are lurking:
./gradlew dependencies
Search for javax.el or tomcat-el entries—you should only see versions matching 7.0.76, no 3.x versions of javax.el-api.
Quick Notes to Avoid Headaches
- Stick to Spring Boot 2.7.x: Newer 2.x branches (like 2.8+) dropped support for Tomcat 7, so this is your safest bet.
- Don't use generic javax.el-api: Tomcat 7 uses its own Apache-branded EL implementations, so using
tomcat-el-apiinstead of the standardjavax.el-apiavoids classloader mismatches. - Check your WAR's lib folder: After building, make sure
WEB-INF/libdoesn't containtomcat-embed-el-*.jarorjavax.el-api-3.x.jar—these would clash with Tomcat's native libraries.
内容的提问来源于stack exchange,提问作者coderatchet

