Maven+spring MVC: org.springframework.web.servlet.DispatcherServlet that does not implement interface javax.servlet.Servlet

1. Problem

When build maven web application, and after that added spring mvc dispatcherServlet for spring 4 i got this issue

"org.springframework.web.servlet.DispatcherServlet" that does not implement 
 interface javax.servlet.Servlet

This is web.xml file

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>SpringMVC4-Hibernate4</display-name>
    <servlet>
      <servlet-name>spring</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
      <servlet-name>spring</servlet-name>
      <url-pattern>*.do</url-pattern>
    </servlet-mapping>
</web-app>

2. Cause

You are missing servlet-api in maven dependency

3. Solution
Add following lines to your pom.xml

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>

the element <scope>provided</scope> that mean: this lib will provide at runtime by container check this link for more detail

Leave a Reply