org.springframework.web.servlet.DispatcherServlet cannot be cast to javax.servle

来源:互联网 发布:淘宝的淘气值有什么用 编辑:程序博客网 时间:2024/05/22 10:36

from http://chenzehe.iteye.com/blog/1466031

调试Spring MVC时发现如下异常:

java.lang.ClassCastException: org.springframework.web.servlet.DispatcherServlet cannot be cast to javax.servlet.Servlet

 

问题出在servlet-api.jar上,tomcat部署springMVC项目时是不用这个包的,而用maven构建项目时需要,如果不引用该依赖就会不识别  HttpServletRequest等的类

解决方法是在maven引用servlet的依赖时,加上属性范围<scope>provided</scope>


而在引用javax.servlet.jsp的依赖时,如果也没有加上 属性范围<scope>provided</scope>,则也会抛出如下异常:

org.apache.jasper.JasperException: Unable to read TLD "META-INF/c.tld" from JAR file "file:/E:/chenzehe/mvnrepo/javax/servlet/jstl/1.2/jstl-1.2.jar": org.apache.jasper.JasperException: Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV

附:
依赖范围(scope)主源码classpath可用测试源码classpath可用会被打包compile 缺省值TRUETRUETRUEtestFALSETRUEFALSEruntimeFALSETRUETRUEprovidedTRUETRUEFALSE
0 0