2017-08-23 113 views
1

我正在使用Spring Tool Suite处理Spring中的webapp。如果我使用IDE在所提供的Pivotal tc服务器上构建和部署应用程序,那么它工作得很好。但是,如果我做一个手动“MVN清洁套装”建设,并试图将其部署到一个独立的Tomcat服务器(使用最新的Tomcat 7),它抛出以下异常:java.lang.NoClassDefFoundError:javax/el/ELManager

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 

经进一步检查,它不抱怨几行字上面关于没有加载罐高:

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 

我的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> 

什么是对这种现象的原因以及如何解决这个问题?

编辑的更多信息:

添加<scope>provided</scope>javax.servlet-api似乎解决约javax.servlet-api不是在开始装载的警告。 el-api问题仍然存在。

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

SOLUTION

除了上述关于javax.servlet-api的问题el-api编辑的部分是,我是在2.2版本中运行一个Tomcat 7提供el-api罐子。缺失的类是在el-api 3.0中引入的。在Tomcat 8中运行相同的webapp(使用el-api 3.0 jar)可以正常工作。

+0

这是否帮助? https://stackoverflow.com/questions/15601469/jar-not-loaded-see-servlet-spec-2-3-section-9-7-2-offending-class-javax-serv – GhostCat

+0

@GhostCat解决了这个问题加载'javax.servlet-api-xyzjar',即将'提供的'添加到'javax.servlet-api'。然而,我仍然在与'el-api'问题作斗争。在下面的答案下的评论更多信息。 –

回答

5

您错过了javax.el-api作为依赖关系。地址:

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

到你的pom.xml

+0

我以前试过。事情是 - 我仍然得到这个错误,再加上tomcat告诉我,它在开始部署应用程序时无法加载'el-api' jar。当我查看tomcat/lib目录时,它已经包含了'el-api.jar',这可能是为什么它告诉我它不会加载我在pom.xml中列出的那个。事情是,增加'提供'不修复它。无论我做什么,它仍然抱怨给我相同的'java.lang.NoClassDefFoundError:javax/el/ELManager'错误。 –

+0

@JacekŚlimok你使用哪个版本的javax.el-api? – Jens

+0

至于在tomcat/lib中提供的版本 - jar文件名没有指定它(它是'el-api.jar')。根据MANIFEST.MF里面的版本2.2:https://pastebin.com/sHpZKxrF –