无法在Spring Tool Suite中启动Spring MVC应用程序

时间:2015-01-22 19:43:17

标签: spring spring-mvc spring-tool-suite

我正在使用Spring Tool Suite使用spring框架和maven工具在java中开发MVC Web应用程序。

运行我的应用程序时出现以下错误。

SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.LinkageError: loader constraint violation: when resolving method   "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/WEB_002dINF/view/NewFile_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type org/apache/tomcat/InstanceManager used in the signature
at org.apache.jsp.WEB_002dINF.view.NewFile_jsp._jspInit(NewFile_jsp.java:32)
at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

`Jan 23, 2015 12:55:53 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with     path [/MyMsit] threw exception [java.lang.LinkageError: loader constraint  violation: when resolving method    "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/s ervlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader  (instance of org/apache/jasper/servlet/JasperLoader) of the current class,  org/apache/jsp/WEB_002dINF/view/NewFile_jsp, and the class loader (instance  of java/net/URLClassLoader) for the method's defining class,  org/apache/jasper/runtime/InstanceManagerFactory, have different Class  objects for the type org/apache/tomcat/InstanceManager used in the signature]  with root cause
java.lang.LinkageError: loader constraint violation: when resolving method     "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/WEB_002dINF/view/NewFile_jsp, and the class loader (instance of java/net/URLClassLoader) for the method's defining class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type org/apache/tomcat/InstanceManager used in the signature

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>net.mymsit</groupId>
<artifactId>MyMsit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>MyMsit</name>
<description>Complete Course portal for MSIT Course</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.1.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <!-- Generic properties -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Web -->
    <jsp.version>2.3.1</jsp.version>
    <servlet.version>2.5</servlet.version>


    <!-- Spring -->
    <spring-framework.version>4.1.1.RELEASE</spring-framework.version>

    <!-- Hibernate / JPA -->
    <hibernate.version>4.2.1.Final</hibernate.version>

    <!-- Logging -->

    <slf4j.version>1.7.10</slf4j.version>

    <!-- Test -->
    <junit.version>4.11</junit.version>

</properties>

<dependencies>

    <!-- Spring MVC -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        </dependency>

    <!-- Other Web dependencies -->

    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        </dependency>


    <!-- Test Artifacts -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


    <!-- Boot Artifacts -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core</artifactId>
        <version>2.2.21.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    <dependency>
        <groupId>org.freemarker</groupId>
        <artifactId>freemarker</artifactId>
        </dependency>

    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-facebook</artifactId>
        </dependency>

    <dependency>
        <groupId>org.linkedin</groupId>
        <artifactId>org.linkedin.zookeeper-impl</artifactId>
        <version>1.5.1</version>
    </dependency>


    <dependency>
        <groupId>org.linkedin</groupId>
        <artifactId>org.linkedin.util-groovy</artifactId>
        <version>1.9.0</version>
    </dependency>

</dependencies>

web.xml的内容如下

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     id="WebApp_ID" version="2.5">

<welcome-file-list>

<welcome-file>NewFile.html</welcome-file>

</welcome-file-list>
<display-name>MyMsit</display-name>

<!--
    - Location of the XML file that defines the root application context.
    - Applied by ContextLoaderListener.
-->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/application-config.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<!--
    - Servlet that dispatches request to registered handlers (Controller implementations).
-->
<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

我无法理解错误。任何人都可以帮我解决问题。

3 个答案:

答案 0 :(得分:3)

参考Shrikant的帖子。

使用Tomcat时,您绝对不希望在WEB-INF / lib文件夹中包含Tomcat的jar文件。

这些jar来自于Spring Boot上的Maven依赖项。 指定在你的pom中提供弹簧引导罐,如此

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <scope>provided</scope>
     </dependency>

这让我有点恶化,直到我看着扩展的pom的依赖层次结构,看到了tomcat罐子的来源。一旦我将范围更改为提供而不是在spring-boot依赖项上编译,我的页面加载就好了。

Shrikant - &gt;没有什么可以反对你的答案,我只是不关心从我的lib目录中删除jar然后构建一个战争,当我只需一次清理,打包,安装和部署,点击一个按钮。

答案 1 :(得分:1)

我也面临同样的问题,但我得到了解决方案。
如果您使用的是Tomcat服务器,那么您不能将tomcat的jar文件放入WEB-INF / lib。 Tomcat已经有了类,它们必须由root tomcat类加载器加载,而不是由web-app类加载器加载。
所以检查你的WEB-INF / lib文件夹并删除所有tomcat的jar。(例如:tomcat-api-8.0.0-RC1.jar,tomcat-juli-8.0.0-RC1.jar,tomcat-util -8.0.0-RC1.jar,tomcat-servlet-api-8.0.0-RC1.jar)。

答案 2 :(得分:0)

而不是在web.xml中配置,使用实现SpringBootServletInitializer的类,