ssm项目
问题:配置应用程序监听器[org.springframework.web.context.ContextLoaderListener]错误
启动tomcat报错:
Connected to server
[2021-06-29 07:39:31,718] Artifact ssm-crud:war exploded: Artifact is being deployed, please wait...
29-Jun-2021 19:39:33.978 信息 [RMI TCP Connection(3)-127.0.0.1] org.apache.jasper.servlet.TldScanner.scanJars 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
29-Jun-2021 19:39:34.040 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 一个或多个listeners启动失败,更多详细信息查看对应的容器日志文件
29-Jun-2021 19:39:34.206 警告 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom 使用[SHA1PRNG]创建会话ID生成的SecureRandom实例花费了[165]毫秒。
29-Jun-2021 19:39:34.206 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal 由于之前的错误,Context[/ssm_crud]启动失败
[2021-06-29 07:39:34,219] Artifact ssm-crud:war exploded: Error during artifact deployment. See server log for details.
29-Jun-2021 19:39:41.211 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory 把web 应用程序部署到目录 [C:\Program Files\Apache Software Foundation\Tomcat 10.0\webapps\manager]
29-Jun-2021 19:39:41.289 信息 [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Web应用程序目录[C:\Program Files\Apache Software Foundation\Tomcat 10.0\webapps\manager]的部署已在[78]毫秒内完成
日志信息
29-Jun-2021 19:39:34.039 严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart 配置应用程序监听器[org.springframework.web.context.ContextLoaderListener]错误
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart 由于以前的错误,已跳过安装应用程序侦听器
网上搜到的答案都是说有 maven dependencies 没添加到项目的路径下,在Artifacts中把jar包引入到项目,但是我查看了项目的jar包都是引入进来的,那究竟是什么原因啊?求解求解!!!
补充:只要是在web.xml文档里面监听器这些,tomcat就启动不起来,其他普通的java项目也有同样的问题,这可怎么办啊?
下面是我web.xml里面的内容
<!--启动spring的容器-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--2、springmvc的前端控制器,拦截所有请求 -->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
3、字符编码过滤器,一定要放在所有过滤器之前
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4、使用Rest风格的URI,将页面普通的post请求转为指定的delete或者put请求
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>HttpPutFormContentFilter</filter-name>
<filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HttpPutFormContentFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
tomcat从10换到7,问题解决了
ps:用tomcat10的时候,其他什么都不做,就创建一个普通java项目,在项目里面添加web和springMVC框架,自动配置好web.xml,每有其他任何操作,也会有tomcat启动失败的问题