java - 關(guān)于maven tomcat啟動(dòng)錯(cuò)誤
問(wèn)題描述
maven(命令為 clean tomcat7:run)啟動(dòng)tomcat提示錯(cuò)誤:org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer
自己認(rèn)為是版本沖突問(wèn)題,但是不知道怎么解決。查了下,有人說(shuō)是pom.xml中servlet jar包部分的<scope/>應(yīng)該設(shè)為provided,但自己確實(shí)是這么配置的。下面是pom.xml部分內(nèi)容:
<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>
各位有誰(shuí)遇到過(guò)或者對(duì)此有個(gè)人見(jiàn)解,麻煩給予點(diǎn)撥,謝謝!
----------------------Update-------------------------排錯(cuò)能力實(shí)在有限,還是沒(méi)能解決問(wèn)題。貼一下比較完整的信息吧:
這是啟動(dòng)時(shí)的錯(cuò)誤信息:
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
根據(jù)以上信息我猜測(cè)是tomcat本身的api和springframework.web包有沖突(spring版本4.2.4.RELEASE)spring-web含有一個(gè)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>
本來(lái)想換tomcat8試試的,但是好像也沒(méi)有tomcat8-maven-plugin試過(guò)不包含其它jar包也還是如此,所以該如何是好呢?(╥╯^╰╥)
問(wèn)題解答
回答1:指定下 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>回答2:
包沖突了,查看下其他引用的jar包中是否有servlet-api,用exclusion標(biāo)簽去掉servlet-api
回答3:應(yīng)該是 spring 依賴的 servlet api 包跟 tomcat 7 自帶的 servlet jar 包沖突了吧。把有依賴到 servlet api 的pom 都排除掉。可以用 exclusion標(biāo)簽。
回答4:1.有可能是與其他的包中有沖突2.我猜你應(yīng)該用的不是springboot吧,如果是springboot,它本身是包含完整的tomcat的,所以會(huì)報(bào)錯(cuò).記得不錯(cuò)貌似是會(huì)報(bào)錯(cuò)的.
回答5:
你看看是不是有包沖突,intellij是在這里有個(gè)按鈕(有問(wèn)題的好像是紅色的線)eclipse自己百度下,應(yīng)該差不多,如果有沖突嘗試exclusion排除掉這里有個(gè)和你類似的,也是<scope>provided</scope>,但是還是需要exclusionhttp://powertech.iteye.com/bl...
或者把servlet-api換成3.1.0的試試 鏈接描述stackoverflow上有3.0.1這個(gè)版本也出現(xiàn)問(wèn)題的
相關(guān)文章:
1. mac里的docker如何命令行開(kāi)啟呢?2. docker - 各位電腦上有多少個(gè)容器啊?容器一多,自己都搞混了,咋辦呢?3. nignx - docker內(nèi)nginx 80端口被占用4. docker容器呢SSH為什么連不通呢?5. 關(guān)于docker下的nginx壓力測(cè)試6. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問(wèn)題7. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””8. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問(wèn)題。9. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????10. docker-compose 為何找不到配置文件?

網(wǎng)公網(wǎng)安備