maven报错: previously initiated loading for a different type with name "servlet/http/HttpServletReq

时间:2024-05-18 21:44:32

maven 项目用maven的tomcat插件启动失败

HTTP Status 500 - java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/jasper/servlet/JasperLoader) previously initiated loading for a different type with name “javax/servlet/http/HttpServletRequest”

解决办法:
百度上好多都说这样解决:

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

原因是 配置依赖插件的时候,没有加 <scope>provided</scope>
导致servlet-api的jar或者jsp-api的jar包与tomcat服务器运行时自带的jar包相冲突

这种原因是大多数网友 遇到的问题.

但是,我的项目加了 <scope>provided</scope>依然报错,错误信息还是下面的 没变化,
经过 不懈努力…终于找到了问题的源头:
在自己电脑安装的jdk的jre中还有 一个servlet.jar,就是这个jar与tomcat运行时的jar相冲突了,删掉之后,完美运行~~~~2333
路径:C:\Program Files (x86)\Java\jdk1.8.0_144\jre\lib\ext
具体路径 参考你们自己的jdk安装的路径
maven报错: previously initiated loading for a different type with name "servlet/http/HttpServletReq

网页上的报错信息:

    HTTP Status 500 - java.lang.LinkageError:
     loader constraint violation: loader (instance of org/apache/jasper/servlet/JasperLoader) previously initiated loading for a different type with name 
    "javax/servlet/http/HttpServletRequest"

maven报错: previously initiated loading for a different type with name "servlet/http/HttpServletReq
控制台(tomcat)的报错信息:

严重: Allocate exception for servlet demo2.AServlet
java.lang.ClassCastException: demo2.AServlet cannot be cast to javax.servlet.Servlet
	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

为方便好看,我给分成了两端:

 三月 23, 2019 1:04:23 下午 org.apache.catalina.core.StandardWrapperValve invoke
    严重: Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/jasper/servlet/JasperLoader) previously initiated loading for a different type with name "javax/servlet/http/HttpServletRequest"] with root cause
    java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/jasper/servlet/JasperLoader) previously initiated loading for a different type with name "javax/servlet/http/HttpServletRequest"
    	at java.lang.Class.getDeclaredMethods0(Native Method)
    	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    	at java.lang.Class.getDeclaredMethods(Class.java:1975)
    	at org.apache.catalina.util.Introspection.getDeclaredMethods(Introspection.java:127)
    	at org.apache.catalina.core.DefaultInstanceManager.populateAnnotationsCache(DefaultInstanceManager.java:342)
    	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:161)
    	at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:149)
    	at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:172)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:748)