java.io.IOException: java.lang.ClassCastException: Cannot cast org.springframework.web.SpringServlet

 

 

java.io.IOException: java.lang.ClassCastException: Cannot cast org.springframework.web.SpringServletContainerInitializer to javax.servlet.ServletContainerInitializer
	at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:206)
	at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:158)
	at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1579)
	at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1280)
	at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:888)
	at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:388)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5522)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: Cannot cast org.springframework.web.SpringServletContainerInitializer to javax.servlet.ServletContainerInitializer
	at java.lang.Class.cast(Class.java:3186)
	at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:198)
	... 15 more

 

出现以上问题一般是maven项目里面引用了

ServletContainerInitializer

带有这个类的jar包,很多文章都说是javaee-api,其实不一定是的,而且你可能其实都没有在pom中用到

带有这个类的方法。

这种恶心情况怎么会难倒我这个java老鸟呢。。。。

很简单ctrl+shift+t,当然了eclipse里面,idea执行更换。。。。

就可以直接定位到哪个jar包,如果是pom中有的,加一个provided

如果是pom中没有的,那么通过maven分析命令或者eclipse里面

java.io.IOException: java.lang.ClassCastException: Cannot cast org.springframework.web.SpringServlet_第1张图片

直接搜到,然后找到这个jar pom配置,exclude就OK

java.io.IOException: java.lang.ClassCastException: Cannot cast org.springframework.web.SpringServlet_第2张图片

 

 

你可能感兴趣的:(error)