ServletDispatcher 无法在我的 spring 项目中强制转换为 Javax.servlet.Servlet 异常 [英] ServletDispatcher cannot be cast to Javax.servlet.Servlet exception in my spring project
问题描述
启动tomcat服务器时出现异常
While starting tomcat server I am getting an exception
SEVERE: Servlet /MavenWeb threw load() exception
java.lang.ClassCastException: org.springframework.web.servlet.DispatcherServlet
cannot be cast to javax.servlet.Servlet
我正在使用 spring3,但我的 lib 文件夹中有 jar spring2-5-6,我从 pom.xml 中删除了它,但仍然出现在 lib 文件夹中 - 尽管我不确定这是否是一个问题.我正在使用 Eclipse IDE.谢谢!!
I am using spring3 but there is jar spring2-5-6 in my lib folder, I removed it from pom.xml but still appears in lib folder - though I am not sure if that is an issue. I am using Eclipse IDE. Thanks!!
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Draft-6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1-b01</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflow</artifactId>
<version>1.0.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
推荐答案
您不应该在一个项目中使用多个版本的 Spring JAR,但这不是问题.
You shouldn't be using multiple versions of Spring JARs in one project, but this is not the issue.
该问题很可能是由两个不同的类加载器加载的 servlet API 类引起的.可能您的 WAR 中有 servlet*.jar
或其他一些特定于容器的 JAR.通过在 pom.xml
中将它们的
设置为 provided
来删除它们.
The problem is most likely caused by servlet API classes loaded by two different class-loaders. Probably you have servlet*.jar
or some other container-specific JARs in your WAR. Remove them by setting their <scope>
to provided
in pom.xml
.
这篇关于ServletDispatcher 无法在我的 spring 项目中强制转换为 Javax.servlet.Servlet 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!