Tomcat 7 java.lang.NoClassDefFoundError: javax/el/ELManager

2022-09-04 02:21:49

我想在版本7中将我的应用程序部署到tomcat,并且我得到以下异常,但是如果我尝试将此应用程序部署到tomcat版本8,它可以正常工作。java.lang.NoClassDefFoundError: javax/el/ELManager

你有什么想法如何解决这个问题吗?

为什么我从雄猫8切换到7?在测试环境中,存储库中是 tomcat 8,在服务器上是 tomcat7。

啪.xml

<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 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>certplatform</groupId>
<artifactId>certplatform</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
      <source>1.8</source>
      <target>1.8</target>
    </configuration>
  </plugin>
  <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
      <warSourceDirectory>WebContent</warSourceDirectory>
    </configuration>
  </plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring- 
core -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.0.4.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring- 
context -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>5.0.4.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring- 
context-support -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>5.0.4.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring- 
webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.0.4.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-web 
-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.0.4.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

<!--https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/javax.servlet.jsp.jstl-api -->
<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>javax.servlet.jsp.jstl-api</artifactId>
    <version>1.2.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.5.0-b01</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>6.0.8.Final</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.2.15.Final</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-entitymanager -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.15.Final</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.2.1</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk15on</artifactId>
    <version>1.59</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcpkix-jdk15on</artifactId>
    <version>1.59</version>
</dependency>   

<!-- https://mvnrepository.com/artifact/javax.el/javax.el-api -->
<dependency>
    <groupId>javax.el</groupId>
    <artifactId>javax.el-api</artifactId>
    <version>3.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.el/el-api -->
<dependency>
    <groupId>javax.el</groupId>
    <artifactId>el-api</artifactId>
    <version>2.2</version>
</dependency>   

网.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">

<display-name>spring-mvc-demo</display-name>

<!-- Spring MVC Configs -->

<!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-mvc-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>


答案 1

此问题是由 3.0 版中引入的此类引起的。javax/el/ELManagerel-api

Tomcat 7 附带了预捆绑的 el-api 2.2(缺少该类),它在运行时选择它,而不是你的 el-api jar。

Tomcat 8 具有 el-api 3.0,因此该类存在。javax/el/ELManager

最好能够尽可能近距离地同步开发/测试/生产环境。

当你的测试环境有Tomcat 8时,在开发中针对Tomcat 8进行开发更有意义。正如您发现Tomcat 7和8服务器附带了不同的库集,因此您的代码可以针对这些不同的库集以不同的方式运行。


答案 2

如果你想在生产环境中在 Tomcat 7 上运行你的 webapp,那么你应该在测试环境中使用 Tomcat 7。

发生的事情是,您不小心引入了对EL 3.0 API的依赖性...并将其包含在您的 POM 文件中。它正在Tomcat 8上找到工作。但在Tomcat 7上,该平台支持EL 2.1。因此,当您的应用程序尝试加载...它失败了。javax.el.ELManager

解决 方案:

  • 将您的生产平台升级到 Tomcat 8
  • 将您的开发和测试平台降级到Tomcat 7,并从代码库中消除对较新API的任何依赖性。

Apache Tomcat 版本页面列出了 Tomcat 每个主要版本的各种规范版本。


有没有可能解决这个问题?

如果您准备“屠杀”Tomcat 7服务器,则可以用更新的服务器替换EL实现。但我不会尝试这样做,因为1)它可能根本不起作用,2)结果可能难以维持。而且您有责任让您的运营,质量保证和/或安全团队中风!

是否不可能通过应用程序中的更改来解决此问题?

AFAIK,没有可能。

我认为你可以尝试用这个替换EL依赖关系:

<dependency>
    <groupId>javax.el</groupId>
    <artifactId>javax.el-api</artifactId>
    <version>3.0.0</version>
</dependency>

但它不起作用。根据亚历克斯的评论:

“将JAR添加到应用程序POM并不能解决任何问题。这是Tomcat bootstrap打印出来的消息:“validateJarFile(C:\Software\apache-tomcat-7.0.99\webapps\leonardo-flows-services\WEB-INF\lib\javax.el-api-3.0.0.jar) - jar未加载。请参阅 Servlet 规范 3.0,第 10.7.2 节。违规类:javax/el/Expression.class”。它与它的lib罐子相冲突。


推荐