java.lang.NoClassDefFoundError: javax/el/ELManager

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45841464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 02:11:29  来源:igfitidea点击:

java.lang.NoClassDefFoundError: javax/el/ELManager

javamaventomcatnoclassdeffounderror

提问by Jacek ?limok

I'm working on a webapp in Spring using Spring Tool Suite. If I build and deploy the application there using the IDE onto the provided Pivotal tc Server, it works just fine. However, if I do a manual "mvn clean package" build and attempt to deploy it to a standalone Tomcat server (using newest Tomcat 7), it throws the following exception:

我正在使用 Spring Tool Suite 在 Spring 中开发一个 webapp。如果我使用 IDE 在那里构建应用程序并将其部署到提供的 Pivotal tc Server 上,它就可以正常工作。但是,如果我执行手动“mvn clean package”构建并尝试将其部署到独立的 Tomcat 服务器(使用最新的 Tomcat 7),则会引发以下异常:

2017-08-23 15:24:13 WARN  AnnotationConfigWebApplicationContext:551 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcValidator' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager
2017-08-23 15:24:13 ERROR DispatcherServlet:502 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: Factory method 'requestMappingHandlerAdapter' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcValidator' defined in org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/el/ELManager

Upon further inspection, it does complain few lines higher above about not loading jars:

经过进一步检查,它确实抱怨上面没有加载罐子的几行:

sie 23, 2017 3:24:12 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT.war
sie 23, 2017 3:24:12 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT\WEB-INF\lib\el-api-2.2.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
sie 23, 2017 3:24:12 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT\WEB-INF\lib\javax.servlet-api-3.1.0.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
sie 23, 2017 3:24:12 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(D:\Apache-Tomcat-7.0\webapps\TestApp-0.0.1-SNAPSHOT\WEB-INF\lib\tomcat-el-api-8.0.21.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/el/Expression.class
2017-08-23 15:24:13 INFO  ContextLoader:304 - Root WebApplicationContext: initialization started

My pom.xml:

我的 pom.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>com.exmaple.mvc</groupId>
  <artifactId>TestApp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.3.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>4.3.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.6</version>
    </dependency>
    <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
       <version>1.2.17</version>
       <exclusions>
        <exclusion>
            <artifactId>jms</artifactId>
            <groupId>javax.jms</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jmxri</artifactId>
            <groupId>com.sun.jmx</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jmxtools</artifactId>
            <groupId>com.sun.jdmk</groupId>
            </exclusion>
        </exclusions>
    </dependency>
        <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.3</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.1.Final</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
  </dependencies>

    <build>
        <plugins>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        </plugins>
    </build>

</project>

What's the reason for this behavior and how can I solve this?

这种行为的原因是什么,我该如何解决?

EDITMore information:

编辑更多信息:

Adding <scope>provided</scope>to javax.servlet-apiseems to fix the warning about javax.servlet-apinot being loaded at the start. Problem with el-apistill remains.

添加<scope>provided</scope>javax.servlet-api似乎修复了关于javax.servlet-api在开始时未加载的警告。问题el-api仍然存在。

I've checked the tomcat/lib directory and it already contains el-api.jarin it, which is likely why it tells me it's not going to load the one I list in pom.xml. The thing is, adding <scope>provided</scope>doesn't fix it either. Whatever I do, it still complains gives me the same java.lang.NoClassDefFoundError: javax/el/ELManagererror.

我检查了 tomcat/lib 目录,它已经包含el-api.jar在其中,这可能是它告诉我它不会加载我在 pom.xml 中列出的那个的原因。问题是,添加<scope>provided</scope>也不能解决问题。无论我做什么,它仍然抱怨给我同样的java.lang.NoClassDefFoundError: javax/el/ELManager错误。

SOLUTION

解决方案

In addition to the part in the edit above regarding javax.servlet-apithe problem with el-apiwas that I was running a Tomcat 7 with provided el-apijar in version 2.2. The missing class was introduced in el-api 3.0. Running the same webapp in Tomcat 8 (with el-api 3.0 jar) works properly.

除了上面编辑中关于javax.servlet-api问题的部分之外el-api,我正在运行带有el-api2.2 版提供的jar的 Tomcat 7 。缺失的类是在 el-api 3.0 中引入的。在 Tomcat 8(使用 el-api 3.0 jar)中运行相同的 webapp 可以正常工作。

采纳答案by Jens

You miss the javax.el-apias dependency. Add:

你错过了javax.el-apias 依赖。添加:

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

to your pom.xml

到你的 pom.xml

回答by Nandan kelkar

Please refer to Hibernate validation "Unable to initialize javax.el.ExpressionFactory" error

请参考Hibernate 验证“无法初始化 javax.el.E​​xpressionFactory”错误

use

<dependency>
   <groupId>org.glassfish</groupId>
   <artifactId>javax.el</artifactId>
   <version>3.0.1-b08</version>
</dependency>

回答by Khan

In my case, Commented out this dependency,

就我而言,注释掉了这种依赖关系,

<!-- <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.8.Final</version>
    </dependency> -->

and added

并添加

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

This solved my issue

这解决了我的问题

回答by Terran

Try the following:

请尝试以下操作:

  • Add javax.eland javax.el-apito the pom.xml as others mention
  • If you have different classloaders - as often the case when using OSGi - you need to temporarily set the context to the one holding the implementation. Wrap your call with:

    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      Class<?> currentClass = this.getClass(); // or any class that is in a bundle with the dependency 
      Thread.currentThread().setContextClassLoader(currentClass.getClassLoader());
      // execute library call
    } finally {
      Thread.currentThread().setContextClassLoader(originalClassLoader); // back to original context
    }
    
  • Add a service to META-INF/services/

  • Add a property to $java.home/lib/el.properties
  • Use the system property with the factoryId
  • javax.eljavax.el-api其他人提到的一样添加到 pom.xml
  • 如果你有不同的类加载器——就像使用 OSGi 时的情况一样——你需要临时将上下文设置为保存实现的上下文。用以下内容结束您的通话:

    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
      Class<?> currentClass = this.getClass(); // or any class that is in a bundle with the dependency 
      Thread.currentThread().setContextClassLoader(currentClass.getClassLoader());
      // execute library call
    } finally {
      Thread.currentThread().setContextClassLoader(originalClassLoader); // back to original context
    }
    
  • 向 META-INF/services/ 添加服务

  • 向 $java.home/lib/el.properties 添加属性
  • 使用带有 factoryId 的系统属性

When the library is instantiating the ExpressionFactoryvia > ELManager.newInstance(..)> FactoryFinder.find(..)it has several strategies to find an implementation. The call is hardcoded like this:

如果库的实例ExpressionFactory经> ELManager.newInstance(..)>FactoryFinder.find(..)它有几个策略,以找到一个实现。调用是这样硬编码的:

public static ExpressionFactory newInstance(Properties properties) {
    return (ExpressionFactory) FactoryFinder.find(
        "javax.el.ExpressionFactory", "com.sun.el.ExpressionFactoryImpl", properties);
}

See source of javax.el.FactoryFinder.find(..)for further information

请参阅 来源以javax.el.FactoryFinder.find(..)获取更多信息

回答by GabrielRado

I'm using Tomcat 7.0.9 and couldn't change to any newer one due my company bureaucracy. Importing EL as a dependency didn't solve it either.

我使用的是 Tomcat 7.0.9,由于我公司的官僚作风,无法更改为任何更新的版本。将 EL 作为依赖项导入也没有解决它。

At Tomcat's root folder -> lib I replaced old el-api (2.2 version of it) with a new 3.0 (from local .m2\repository\javax\el\javax.el-api\3.0.0). Then, isolating tomcat's dependencies correctly (as shown here) made my WAR be correctly deployed at Tomcat 7.0.9

在 Tomcat 的根文件夹 -> lib 我用新的 3.0(来自本地.m2\repository\javax\el\javax.el-api\3.0.0)替换了旧的 el-api(它的 2.2 版本)。然后,正确隔离Tomcat的依赖关系(如图所示这里)使我的WAR被正确部署在Tomcat的7.0.9

回答by CuriousRookie

Hibernate Validator 6.x -> Bean Validation 2.0 (JSR 380) -> EL3.0

Hibernate Validator 6.x -> Bean Validation 2.0 (JSR 380) -> EL3.0

Hibernate Validator 5.x -> Bean Validation 1.1 (JSR 349) -> EL2.2

Hibernate Validator 5.x -> Bean Validation 1.1 (JSR 349) -> EL2.2

Bean Validation 1.0 (JSR 303) -> (I'm not sure)

Bean 验证 1.0 (JSR 303) ->(我不确定)

so,it also influence others version (tomcat,jdk,jsp,servlet)

所以,它也会影响其他版本(tomcat、jdk、jsp、servlet)

such as tomcat7, if you want to use Hibernate Validator, should use Hibernate Validator 5.x, el 2.2 (and servlet 3.0, jsp 2.2 and jdk 6+)

比如tomcat7,如果要使用Hibernate Validator,应该使用Hibernate Validator 5.x、el 2.2(以及servlet 3.0、jsp 2.2和jdk 6+)

回答by Андрей Ким

Downgrade hibernate-validator to version 5 and it will work fine with Tomcat 7. In my case I add next dependency to my pom:

将 hibernate-validator 降级到版本 5,它可以在 Tomcat 7 上正常工作。在我的情况下,我将下一个依赖项添加到我的 pom:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.4.3.Final</version>
</dependency>

Or you can add newer el-api.jat to tomcat lib folder.

或者您可以将更新的 el-api.jat 添加到 tomcat lib 文件夹。