[英]java.lang.NoClassDefFoundError: javax/el/ELManager
I'm working on a webapp in Spring using Spring Tool Suite.我正在使用 Spring Tool Suite 在 Spring 中开发 webapp。 If I build and deploy the application there using the IDE onto the provided Pivotal tc Server, it works just fine.如果我使用 IDE 在那里构建应用程序并将其部署到提供的 Pivotal tc Server 上,它就可以正常工作。 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:但是,如果我执行手动“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?这种行为的原因是什么,我该如何解决?
EDIT More information:编辑更多信息:
Adding <scope>provided</scope>
to javax.servlet-api
seems to fix the warning about javax.servlet-api
not being loaded at the start.将<scope>provided</scope>
到javax.servlet-api
似乎修复了有关javax.servlet-api
未在开始时加载的警告。 Problem with el-api
still remains. el-api
问题仍然存在。
I've checked the tomcat/lib directory and it already contains el-api.jar
in it, which is likely why it tells me it's not going to load the one I list in pom.xml.我检查了 tomcat/lib 目录,它已经包含el-api.jar
,这可能是它告诉我它不会加载我在 pom.xml 中列出的那个的原因。 The thing is, adding <scope>provided</scope>
doesn't fix it either.问题是,添加<scope>provided</scope>
也不能解决它。 Whatever I do, it still complains gives me the same java.lang.NoClassDefFoundError: javax/el/ELManager
error.无论我做什么,它仍然抱怨给我同样的java.lang.NoClassDefFoundError: javax/el/ELManager
错误。
SOLUTION解决方案
In addition to the part in the edit above regarding javax.servlet-api
the problem with el-api
was that I was running a Tomcat 7 with provided el-api
jar in version 2.2.除了上面编辑中关于javax.servlet-api
的部分之外, el-api
javax.servlet-api
的问题是我正在运行带有 2.2 版中提供的el-api
jar 的 Tomcat 7。 The missing class was introduced in el-api 3.0.缺失的类是在 el-api 3.0 中引入的。 Running the same webapp in Tomcat 8 (with el-api 3.0 jar) works properly.在 Tomcat 8(使用 el-api 3.0 jar)中运行相同的 webapp 可以正常工作。
You miss the javax.el-api
as dependency.您错过了javax.el-api
作为依赖项。 Add:添加:
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
to your pom.xml到你的 pom.xml
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+)
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 文件夹。
Please refer to Hibernate validation "Unable to initialize javax.el.ExpressionFactory" error请参考Hibernate 验证“无法初始化 javax.el.ExpressionFactory”错误
use使用
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b08</version>
</dependency>
I'm using Tomcat 7.0.9 and couldn't change to any newer one due my company bureaucracy.我使用的是 Tomcat 7.0.9,由于我公司的官僚作风,无法更改为任何更新的版本。 Importing EL as a dependency didn't solve it either.将 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
).在 Tomcat 的根文件夹 -> lib 我用新的 3.0(来自本地.m2\\repository\\javax\\el\\javax.el-api\\3.0.0
)替换了旧的 el-api(它的 2.2 版本)。 Then, isolating tomcat's dependencies correctly (as shown here ) made my WAR be correctly deployed at Tomcat 7.0.9然后,正确隔离Tomcat的依赖关系(如图所示这里)使我的WAR被正确部署在Tomcat的7.0.9
Adding my answer for those having Tomcat 7 and trying to apply selected answer.为那些拥有 Tomcat 7 并尝试应用所选答案的人添加我的答案。
If adding dependency does not help you and you continue getting如果添加依赖项对您没有帮助并且您继续获得
java.lang.NoClassDefFoundError: javax/el/ELManager
that's because Tomcat 7 will not allow you to load a more modern jar with objects from javax.*
package.那是因为 Tomcat 7 不允许您使用javax.*
包中的对象加载更现代的 jar。 It will print to the log:它将打印到日志:
jakarta.el-3.0.3.jar - jar not loaded. jakarta.el-3.0.3.jar - jar 未加载。 See Servlet Spec 3.0, section 10.7.2.请参阅 Servlet 规范 3.0,第 10.7.2 节。 Offending class: javax/el/Expression.class违规类:javax/el/Expression.class
The solution will be to either upgrade your Tomcat or downgrade hibernate-validator to the latest 5.x version.解决方案是升级 Tomcat 或将 hibernate-validator 降级到最新的 5.x 版本。 Another (less preferred from my POV) option would be to try to replace jars in your tomcat7/lib folder.另一个(从我的 POV 中不太喜欢)选项是尝试替换 tomcat7/lib 文件夹中的 jar。
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这解决了我的问题
Try the following:请尝试以下操作:
javax.el
and javax.el-api
to the pom.xml as others mention正如其他人提到的,将javax.el
和javax.el-api
添加到 pom.xmlIf you have different classloaders - as often the case when using OSGi - you need to temporarily set the context to the one holding the implementation.如果你有不同的类加载器——就像使用 OSGi 时的情况一样——你需要临时将上下文设置为保存实现的上下文。 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/向 META-INF/services/ 添加服务
When the library is instantiating the ExpressionFactory
via > ELManager.newInstance(..)
> FactoryFinder.find(..)
it has several strategies to find an implementation.如果库实例化ExpressionFactory
经> ELManager.newInstance(..)
> FactoryFinder.find(..)
它有几个策略,以找到一个实现。 The call is hardcoded like this:调用是这样硬编码的:
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(..)
源代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.