java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name

Narkan picture Narkan · Dec 30, 2015 · Viewed 14.4k times · Source

When I try run my project I get error

Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name dispatcher
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3156)
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3135)
    at org.apache.catalina.startup.ContextConfig.configureContext(ContextConfig.java:1372)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1176)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 6 more

My web.xml:

<servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>dispatcher</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>

Answer

Rajnikant Patel picture Rajnikant Patel · Dec 30, 2015

The <servlet-name> of the <servlet-mapping> entry must be exactly the same as the <servlet-name> of the <servlet> entry.

So, in your specific case, change this line in <servlet-mapping> entry

<servlet-name>dispatcher</servlet-name>

to

<servlet-name>DispatcherServlet</servlet-name>