Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServletDispatcher cannot be cast to Javax.servlet.Servlet exception in my spring project

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

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>
like image 756
Manth Avatar asked Jul 28 '12 19:07

Manth


1 Answers

You shouldn't be using multiple versions of Spring JARs in one project, but this is not the issue.

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.

like image 63
Tomasz Nurkiewicz Avatar answered Oct 18 '22 07:10

Tomasz Nurkiewicz