title: Spring MVC : Error creating bean with name 'HandlerMapping' defined in ServletContext resource
body: <p>I am new to spring, I am trying to create simple spring MVC application. But unfortunate I am getting error Error "creating bean with name 'HandlerMapping' defined in ServletContext resource". </p>
  
  <p>Please find my files below and correct me where I am going wrong: </p>
  
  <p><strong>Web.xml :</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;FirstSpringMVC&lt;/display-name&gt;
  
   &lt;!-- The front controller of this Spring Web application, responsible for handling all application requests --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;!-- Map all requests to the DispatcherServlet for handling --&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>spring-dispatcher-servlet.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;context:component-scan base-package="org.springframework.samples.petclinic.web"/&gt;
  
  
      &lt;!-- Helper controller class --&gt;
      &lt;bean id="HandlerMapping"
          class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"
      &gt;&lt;/bean&gt;
  
      &lt;!-- Req. process Controller class --&gt;
      &lt;bean name="/Welcome.html" class="C:/Users/Vijay Mekala/Desktop/SAP/Java Spring/FirstSpringMVC/src/com/vijay/hellocontroller/HelloController"&gt;&lt;/bean&gt;
  
      &lt;!-- View Resolver class --&gt;
      &lt;bean id="ViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceviewResolver"
      &gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>- HelloController</strong></p>
  
  <pre><code>package com.vijay.hellocontroller;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.AbstractController;
  
  public class HelloController extends AbstractController{
  
      @Override
      protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
  
          ModelAndView modelandview = new ModelAndView("Hellopage");
          modelandview.addObject("welcomemessage", "Welcome to MVC 1st Application");
  
          return modelandview;
  
  //      return null;
      }
  
  }
  </code></pre>
  
  <p><strong>HelloPage.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;First MVC App OM&lt;/title&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
  &lt;h2&gt;
  ${welcomemessage}
  &lt;/h2&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Few more details:</p>
  
  <p>I am trying to create my 1st Spring MVC application without annotations. So herewith my URL request '<a href="http://localhost:8080/FirstSpringMVC/Welcome.html" rel="nofollow noreferrer">http://localhost:8080/FirstSpringMVC/Welcome.html</a>' which invokes my code. </p>
  
  <p>Herewith my list of errors for reference :</p>
  
  <p>Root Cause --> </p>
  
  <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HandlerMapping' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [/FirstSpringMVC/src/HelloController/HelloController] for bean with name '/Welcome.html' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: /FirstSpringMVC/src/HelloController/HelloController
  Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [/FirstSpringMVC/src/HelloController/HelloController] for bean with name '/Welcome.html' defined in ServletContext resource</p>
  
  <p>Root Cause -></p>
  
  <p>org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [/FirstSpringMVC/src/HelloController/HelloController] for bean with name '/Welcome.html' defined in ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: /FirstSpringMVC/src/HelloController/HelloController
      org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1385)</p>
  
  <p>Root Cause --></p>
  
  <p>java.lang.ClassNotFoundException: /FirstSpringMVC/src/HelloController/HelloController</p>