关于Servlet-api.jar的几个版本问题

bpqqop 2015-10-19 06:31:10
是这样的,我想把Tomcat的lib中的jar加入到MAVEN中进行统一管理(现在是把lib目录加入到classpath),然后发现有两个servlet-api
一个是

另一个是


不管用哪个jar都会报类型转换错误
Cannot cast org.springframework.web.SpringServletContainerInitializer to javax.servlet.ServletContainerInitializer

各路神仙,这两个Servlet-Api跟tomcat/lib下的servlet-api有什么不同,该怎么解决呢?
ps:springMVC4.1.0
...全文
3283 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
雷霆圣剑师 2015-11-04
  • 打赏
  • 举报
回复
可以看看是否是编译执行文件的问题,maven jar更新好了,但是编译文件还是错误的jar包,还有就用tomcat自带的servlet-api.jar
街头小贩 2015-10-22
  • 打赏
  • 举报
回复
引用 9 楼 bpqqop 的回复:
[quote=引用 8 楼 xiaofanku 的回复:] 贴错:
        <!-- service依赖检查@xiaofanku-->
       <context:annotation-config />
大体了看了看代码。下午有时间我在本地试一试。你也可以开启依赖检查属性:dependency-check,
NO~~ 突然发现用的是32为的tomcat,JDK却是64位的..... 可还是不行啊~ 继续调试中.大虾费心了~[/quote] 还没调你的demo.自已可以从头检查一下。我粗略看可能是spring注入失败
街头小贩 2015-10-20
  • 打赏
  • 举报
回复
贴错:
        <!-- service依赖检查@xiaofanku-->
       <context:annotation-config />
大体了看了看代码。下午有时间我在本地试一试。你也可以开启依赖检查属性:dependency-check,
街头小贩 2015-10-20
  • 打赏
  • 举报
回复
引用 6 楼 bpqqop 的回复:
[quote=引用 4 楼 xiaofanku 的回复:] 不允许servlet.jar出现在web-inf/lib中。在你的maven添加

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
添加scope这个也报错~ 没必要引两个 我只引了一个!因为报错所以换成了另外一个,还是报错~ 我没有把他放到webinf的lib下边,那边是空的。 我把他弄到github上了,大虾有空看看,就是搭个环境搞着玩的 https://github.com/yoboygo/wxResume.git [/quote] 试试在下面这个配置文件中添加:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:mvc="http://www.springframework.org/schema/mvc"  
     xmlns:jdbc="http://www.springframework.org/schema/jdbc"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
	     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
	     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
	     http://www.springframework.org/schema/mvc  http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd  
	     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
	     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
	     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd ">
   	<!--   	加载注解驱动 -->
  	<mvc:annotation-driven/>  
	<!--    自动装配 -->
  	<context:component-scan base-package="tk.codecube.wx"></context:component-scan>
        <!-- 依赖检查@xiaofanku-->
        <mvc:annotation-driven />
	<!--   	静态资源 -->
  	<mvc:resources location="/js/" mapping="/js/**"/>
  	<mvc:resources location="/css/" mapping="/css/**"/>
  	<mvc:resources location="/imges/" mapping="/imges/**"/>
  	
	<!--   	配置springMVC的JSP路径 -->
  	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <property name="prefix" value="/WEB-INF/jsp" />  
        <property name="suffix" value=".jsp" />  
    </bean> 
    
  	
 </beans>
如果是注入@service,可以把@service注解的类移到全局上下中的配置中(从mvc上下文 中移出)contextConfigLocation参数指定的文件中.
bpqqop 2015-10-20
  • 打赏
  • 举报
回复
引用 8 楼 xiaofanku 的回复:
贴错:
        <!-- service依赖检查@xiaofanku-->
       <context:annotation-config />
大体了看了看代码。下午有时间我在本地试一试。你也可以开启依赖检查属性:dependency-check,
NO~~ 突然发现用的是32为的tomcat,JDK却是64位的..... 可还是不行啊~ 继续调试中.大虾费心了~
bpqqop 2015-10-19
  • 打赏
  • 举报
回复
引用 4 楼 xiaofanku 的回复:
不允许servlet.jar出现在web-inf/lib中。在你的maven添加

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
添加scope这个也报错~ 没必要引两个 我只引了一个!因为报错所以换成了另外一个,还是报错~ 我没有把他放到webinf的lib下边,那边是空的。 我把他弄到github上了,大虾有空看看,就是搭个环境搞着玩的 https://github.com/yoboygo/wxResume.git
街头小贩 2015-10-19
  • 打赏
  • 举报
回复
有必要引用两个servlet.jar吗
街头小贩 2015-10-19
  • 打赏
  • 举报
回复
不允许servlet.jar出现在web-inf/lib中。在你的maven添加

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
bpqqop 2015-10-19
  • 打赏
  • 举报
回复
引用 1 楼 xiaofanku 的回复:
哪你说的这两个 servlet api版 本是多少?servlet规范不允许servlet.jar放到项目的路径中。 贴一下你报类型转换错误的代码
不允许在项目路径中该怎么理解?
bpqqop 2015-10-19
  • 打赏
  • 举报
回复
引用 1 楼 xiaofanku 的回复:
哪你说的这两个 servlet api版 本是多少?servlet规范不允许servlet.jar放到项目的路径中。 贴一下你报类型转换错误的代码
========================================因为我用的是7.0.52的tomcat================================== <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>7.0.52</version> </dependency> ================================================================================================ <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> ============================================================================================== 十月 19, 2015 7:23:41 下午 org.apache.catalina.startup.ContextConfig processServletContainerInitializers 严重: Failed to process JAR found at URL [/wx] for ServletContainerInitializers for context with name [{1}] 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:196) at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:152) at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1543) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1265) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:873) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:371) 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:5355) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 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:3369) at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:188) ... 15 more
街头小贩 2015-10-19
  • 打赏
  • 举报
回复
哪你说的这两个 servlet api版 本是多少?servlet规范不允许servlet.jar放到项目的路径中。 贴一下你报类型转换错误的代码

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧