关于java-ee:JavaEE-tomcat10踩坑记录

40次阅读

共计 5003 个字符,预计需要花费 13 分钟才能阅读完成。

1. 工具介绍

  1. tomcat: stable 10.0.6
  2. IDEA 2021.1.1
  3. maven: stable 3.8.1

2. 过程形容

  1. 应用 idea 间接创立我的项目选用 java enterprise
  2. 我的项目主动生成 pom 文件, 引入 servlet-api 的依赖

    1.  <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>javax.servlet-api</artifactId>
           <version>4.0.1</version>
           <scope>provided</scope>
  3. 编写我的项目没有问题, 运行我的项目当前动态资源没问题,servlet 报错

        HTTP 状态 500 - 外部服务器谬误
    
        ------
    
        ** 类型 ** 异样报告
    
        ** 音讯 ** 实例化 Servlet 类 [com.xrluo.ee.HelloServlet] 异样
    
        ** 形容 ** 服务器遇到一个意外的状况,阻止它实现申请。** 例外情况 **
    
        jakarta.servlet.ServletException: 实例化 Servlet 类 [com.xrluo.ee.HelloServlet] 异样
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
            org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
            org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
            org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
            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)
        ** 根本原因。**
        java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
            java.lang.ClassLoader.defineClass1(Native Method)
            java.lang.ClassLoader.defineClass(ClassLoader.java:763)
            java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
            org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470)
            org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
            org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
            org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
            org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
            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)
    
        ** 根本原因。**
        java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1401)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
            java.lang.ClassLoader.defineClass1(Native Method)
            java.lang.ClassLoader.defineClass(ClassLoader.java:763)
            java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
            org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2470)
            org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:866)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1370)
            org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1224)
            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
            org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:353)
            org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
            org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
            org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:870)
            org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1696)
            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)

3. 解决问题

目前迷茫中, 实践来说 maven 会下载我的项目所须要的依赖, 为什么还会与 tomcat 外面的 httpServlet 有关系??

同样遇到坑的小伙伴的文章:
Tomcat10 的坑

欢送大佬解答

正文完
 0