java.lang.NoClassDefFoundError: javax/el/ELManager
Solution 1
You miss the javax.el-api
as dependency. Add:
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
to your pom.xml
Solution 2
Downgrade hibernate-validator to version 5 and it will work fine with Tomcat 7. In my case I add next dependency to my 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.
Solution 3
Hibernate Validator 6.x -> Bean Validation 2.0 (JSR 380) -> EL3.0
Hibernate Validator 5.x -> Bean Validation 1.1 (JSR 349) -> EL2.2
Bean Validation 1.0 (JSR 303) -> (I'm not sure)
so,it also influence others version (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+)
Solution 4
Please refer to Hibernate validation "Unable to initialize javax.el.ExpressionFactory" error
use
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b08</version>
</dependency>
Solution 5
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.
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
J_S
Updated on March 31, 2021Comments
-
J_S almost 3 years
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:
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:
<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>
tojavax.servlet-api
seems to fix the warning aboutjavax.servlet-api
not being loaded at the start. Problem withel-api
still remains.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. The thing is, adding<scope>provided</scope>
doesn't fix it either. Whatever I do, it still complains gives me the samejava.lang.NoClassDefFoundError: javax/el/ELManager
error.SOLUTION
In addition to the part in the edit above regarding
javax.servlet-api
the problem withel-api
was that I was running a Tomcat 7 with providedel-api
jar 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. -
J_S over 6 yearsI've tried it before. The thing is - I still get this error, plus tomcat tells me just like before that it failed to load
el-api
jar when it starts deploying the app. When I look into the tomcat/lib directory, it already containsel-api.jar
in 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 samejava.lang.NoClassDefFoundError: javax/el/ELManager
error. -
Jens over 6 years@JacekŚlimok Which Version of javax.el-api do you use?
-
J_S over 6 yearsAs for the provided version in tomcat/lib - jar file name doesn't specify it (it's
el-api.jar
). According to MANIFEST.MF inside it's version 2.2: pastebin.com/sHpZKxrF -
Jens over 6 years@JacekŚlimok This class was introduced in Version 3.0. So it is not available in 2.2
-
J_S over 6 yearsThis solves my issue. Running it on Tomcat 8 (current newest versionn 8.5.20) works fine. Its provided el-api is version 3.0. Marked this as an answer. If you wish to, you may add that the issue was really with the fact that I was running Tomcat 7 with older el-api.
-
Impulse The Fox about 6 yearsI need it running on Tomcat 7. Any way to do this?
-
zkvarz almost 6 years@JacekŚlimok Thanks a lot, you saved my day! I've run my war file successfully only on Tomcat 8 (8.5.31 to be precise).
-
Krum over 5 yearsWhat is this? What triggers this error? Why is this not documented anywhere except on this one stackoverflow post?
-
Chris Clark about 5 yearsThis was the solution for me. Now I have to explain to our CTO and Chief Architect that Tomcat 7 is not compatible with the app. I should note that I tried deploying the app to Tomcat 9 and this problem was not present, so this may be our opportunity to upgrade 😊
-
Giorgi Tsiklauri almost 5 yearsActually, this is not the proper solution. When running on Tomcat7, you can add el-api explicitly on classpath, but in this case, you will have a conflicting classes available in both - Tomcat libs and your projects dependencies. Running on Tomcat 8 works fine, but adding the el-api results in what I wrote. This post addresses the question further: stackoverflow.com/questions/8487048/…
-
Sanket Mehta almost 4 yearsThanks. I added this dependency along with the javax.el 2.2.4 in my pom. And it works fine.
-
Faraz over 3 yearsThank you Rado for this awesome answer
-
eli almost 3 yearsWorks exactly as i wanted