最近在写一个项目,出现一个玄学报错,尝试各种方式无果,具体现象为访问Servlet时先报错500,刷新后报错404,500报错具体如下:

javax.servlet.ServletException: 实例化Servlet类[xxxx]异常
    org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:542)
    org.apache.catalina. valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org. apache.catalina.valves.AbstractAccessLogValve.invoke (AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:346)
    org.apache.coyote.http11.Http1lProcessor.service(Http11Processor.java:374)
    org. apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:887)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1684)
    org. apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.util.concurrent. ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    org.apache.tomcat.util.threads. TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:748)

具体原因

Maven管理的Servlet和Tomcat的Servlet版本冲突

解决方案

试了网上的导入Tomcat下的Servlet的Jar包,但是似乎没办法解决

最后用Maven管理Tomcat插件解决了问题

pom.xml:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
</plugin>
最后修改:2021 年 04 月 14 日
如果觉得我的文章对你有用,请随意赞赏