title: Error creating bean with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping
body: <p>I am trying to fix below error:</p>
  
  <p><code>Error creating bean with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping'</code> </p>
  
  <p>but still getting following error:</p>
  
  <p><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.web.servlet.handler.AbstractHandlerMapping.obtainApplicationContext()Lorg/springframework/context/ApplicationContext;</code></p>
  
  <p>Below is my setup:</p>
  
  <p><strong>applicationContext.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:cache="http://www.springframework.org/schema/cache"
              xmlns:context="http://www.springframework.org/schema/context"
              xmlns:jee="http://www.springframework.org/schema/jee"
              xmlns:mvc="http://www.springframework.org/schema/mvc"
              xmlns:tx="http://www.springframework.org/schema/tx"
              xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                  http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.3.xsd
                  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
                  http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
                  http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
                  http://www.springframework.org/schema/tx
                  https://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
                  &lt;context:component-scan base-package="com.javatpoint"/&gt;
                  &lt;import resource="classpath:IOC.xml"/&gt;
  
          &lt;/beans&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
            version="3.0"&gt;
            &lt;display-name&gt;Bai Tap&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;springDispatcherServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;!-- Map all requests to the DispatcherServlet for handling --&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;springDispatcherServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>IOC.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:cache="http://www.springframework.org/schema/cache"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:jdbc="http://www.springframework.org/schema/jdbc"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
          http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.3.xsd
          http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
          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-4.3.xsd"&gt;
  
  
  
      &lt;bean id="ds" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close"&gt;
          &lt;property name="driverClassName"
              value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url"
              value="jdbc:mysql://localhost:3306/BaiTap" /&gt;
          &lt;property name="username" value="root" /&gt;
          &lt;property name="password" value="1234" /&gt;
      &lt;/bean&gt;  
  
      &lt;bean id="jdbcTemplate"
          class="org.springframework.jdbc.core.JdbcTemplate"&gt;
          &lt;property name="dataSource" ref="ds"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="edao" class="com.javatpoint.EmployeeDao"&gt;
          &lt;property name="jdbcTemplate" ref="jdbcTemplate"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Employee.java</strong></p>
  
  <pre><code>package com.javatpoint;
  
  public class Employee {
  
      private int id;
      private String name;
      private float salary;
  
      public Employee(int id, String name, float salary) {
          super();
          this.id = id;
          this.name = name;
          this.salary = salary;
      }
  
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public float getSalary() {
          return salary;
      }
      public void setSalary(float salary) {
          this.salary = salary;
      }
  }
  </code></pre>
  
  <p><strong>EmployeeDao.java</strong></p>
  
  <pre><code>package com.javatpoint;
  
  import org.springframework.jdbc.core.JdbcTemplate;
  
  public class EmployeeDao {
      private JdbcTemplate jdbcTemplate;
  
      public JdbcTemplate getJdbcTemplate() {
          return jdbcTemplate;
      }
  
      public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
          this.jdbcTemplate = jdbcTemplate;
      }
  
      public int saveEmployee(Employee e) {
          String query = "insert into employee(id,name,salary) values(" + e.getId() +"," + e.getName() + "," + e.getSalary() +")";
          return jdbcTemplate.update(query);
      }
  
      public int updateEmployee(Employee e) {
          String query = "update employee set name = "+e.getName()+",salary="+e.getSalary()+"where id="+e.getId()+"";
          return jdbcTemplate.update(query);
      }
  
      public int deleteEmployee(Employee e) {
          String query = "delete from employee where id = "+e.getId()+"";
          return jdbcTemplate.update(query);
      }
  }
  </code></pre>
  
  <p><strong>Test.java</strong></p>
  
  <pre><code>package com.javatpoint;
  
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  @Controller
  public class Test {
  
         @RequestMapping("/")
         @ResponseBody
         public static void main(String[] args) {
  
            ApplicationContext context = new ClassPathXmlApplicationContext("IOC.xml");
            EmployeeDao dao = (EmployeeDao) context.getBean("edao");
            int status = dao.saveEmployee(new Employee(102,"Amit",3500));
            System.out.println(status);
      }
  }
  </code></pre>
  
  <blockquote>
    <p>porm.xml  http://maven.apache.org/xsd/maven-4.0.0.xsd">
            4.0.0
            com.javatpoint
            BaiTap
            0.0.1-SNAPSHOT
            war</p>
  </blockquote>
  
  <pre><code>    &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.12&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;5.1.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-core --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;5.1.5.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;4.0.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-context --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;4.3.13.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/aspectj/aspectjrt --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjrt&lt;/artifactId&gt;
              &lt;version&gt;1.5.3&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.aspectj&lt;/groupId&gt;
              &lt;artifactId&gt;aspectjweaver&lt;/artifactId&gt;
              &lt;version&gt;1.9.4&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.4&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;8.0.15&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-tx --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
              &lt;version&gt;5.1.8.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-orm --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;5.1.8.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>