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包也还是如此,所以该如何是好呢?(╥╯^╰╥)
3 回答
炎炎设计
TA贡献1808条经验 获得超4个赞
应该是 spring 依赖的 servlet api 包跟 tomcat 7 自带的 servlet jar 包冲突了吧。
把有依赖到 servlet api 的pom 都排除掉。可以用 exclusion标签。
慕仙森
TA贡献1827条经验 获得超7个赞
指定下 Servlet API 的版本试试看:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
添加回答
举报
0/150
提交
取消