maven使用tomcat插件启动项目

2018-03-19  本文已影响80人  loserStar

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

调试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

附:


image.png
上一篇下一篇

猜你喜欢

热点阅读