maven(命令为 clean tomcat7:run)启动tomcat提示错误:
org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer
自己认为是版本冲突问题,但是不知道怎么解决。
查了下,有人说是pom.xml中servlet jar包部分的<scope/>应该设为provided,但自己确实是这么配置的。
下面是pom.xml部分内容:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<scope>provided</scope>
</dependency>
各位有谁遇到过或者对此有个人见解,麻烦给予点拨,谢谢!
----------------------Update-------------------------
排错能力实在有限,还是没能解决问题。
贴一下比较完整的信息吧:
Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer
at org.apache.catalina.startup.ContextConfig.getServletContainerInitializer(ContextConfig.java:1670)
at org.apache.catalina.startup.ContextConfig.getServletContainerInitializers(ContextConfig.java:1652)
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1562)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
根据以上信息我猜测是tomcat本身的api和springframework.web包有冲突(spring版本4.2.4.RELEASE)
spring-web含有一个javax.servlet-api的依赖:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
自己pom.xml配置的servlet是
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api.version}</version> <!--引用2.5-->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-api.version}</version> <!--引用2.0-->
<scope>provided</scope>
</dependency>
tomcat使用的是:
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<path>/</path>
<port>8080</port>
</configuration>
本来想换tomcat8试试的,但是好像也没有tomcat8-maven-plugin
试过不包含其它jar包也还是如此,所以该如何是好呢?(╥╯^╰╥)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…