title: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping'
body: <p>Use jdk 1.8</p>
  
  <ol>
  <li>SpringMVC-4.3.3</li>
  <li>SpringCore-4.3.3</li>
  <li>javax.servlet-api-3.0.1</li>
  <li>spring-data-jpa:1.10.4</li>
  <li>hibernate-entitymanager:4.2.5.Final</li>
  <li>hibernate-core:4.2.5.Final</li>
  <li>Simple Logging Facade for Java:1.6.1</li>
  </ol>
  
  <p>I encountered with such error</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping':
    Invocation of init method failed; nested exception is
    java.lang.NoSuchMethodError:
    org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation</p>
  </blockquote>
  
  <p><strong>My question</strong>:<br>
  Why error encoured and how fix it?</p>
  
  <p><em>web.xml</em></p>
  
  <pre><code>&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
       version="3.1"&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;product&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;product&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p></p>
  
  <p><em>product-servlet.xml</em></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.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.xsd"&gt;
  
  &lt;bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/"/&gt;
      &lt;property name="suffix" value=".jsp"/&gt;
  &lt;/bean&gt;
  &lt;context:component-scan base-package="com.kopylov.spring.controller" /&gt;
  &lt;mvc:annotation-driven/&gt;
  </code></pre>
  
  <p></p>
  
  <p><em>Controller</em></p>
  
  <pre><code>import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  @Controller
  public class ProductController {
  
  @RequestMapping
  public String showHome(){
      return "home";
  }
  </code></pre>
  
  <p>}</p>
  
  <p><em>AppInitializer</em></p>
  
  <pre><code>import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
  </code></pre>
  
  <p>public class AppInitializer extends            AbstractAnnotationConfigDispatcherServletInitializer {</p>
  
  <pre><code>@Override
  protected Class&lt;?&gt;[] getRootConfigClasses(){
      return new Class&lt;?&gt;[]{
              DataConfig.class
      };
  }
  
  @Override
  protected Class&lt;?&gt;[] getServletConfigClasses(){
      return new Class&lt;?&gt;[0];
  }
  
  @Override
  protected String[] getServletMappings(){
      return new String[0];
  }
  </code></pre>
  
  <p>}</p>
  
  <p><em>DataConfig</em></p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan("com.kopylov.spring")
  @PropertySource("classpath:/com/kopylov/spring/resources/app.properties")
  @EnableJpaRepositories("com.kopylov.spring.repository")
  public class DataConfig {
  private static final String PROP_DATABASE_DRIVER = "db.driver";
  private static final String PROP_DATABASE_PASSWORD = "db.password";
  private static final String PROP_DATABASE_URL = "db.url";
  private static final String PROP_DATABASE_USERNAME = "db.username";
  private static final String PROP_HIBERNATE_DIALECT = "db.hibernate.dialect";
  private static final String PROP_HIBERNATE_SHOW_SQL = "db.hibernate.dialect";
  private static final String PROP_ENTITYMANAGER_PACKAGES_TO_SCAN = "db.entitymanager.packages.to.scan";
  private static final String PROP_HIBERNATE_HBM2DDL_AUTO = "db.hibernate.hbm2ddl.auto";
  
  @Resource
  private Environment env;
  
  @Bean
  public DataSource dataSource(){
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName(env.getRequiredProperty(PROP_DATABASE_DRIVER));
      dataSource.setUrl(env.getRequiredProperty(PROP_DATABASE_URL));
      dataSource.setUsername(env.getRequiredProperty(PROP_DATABASE_USERNAME));
      dataSource.setPassword(env.getRequiredProperty(PROP_DATABASE_PASSWORD));
  
      return dataSource;
  }
  
  @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactory(){
      LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
      emfb.setDataSource(dataSource());
      emfb.setPersistenceProviderClass(HibernatePersistence.class);
      emfb.setPackagesToScan(env.getRequiredProperty(PROP_ENTITYMANAGER_PACKAGES_TO_SCAN));
      emfb.setJpaProperties(getHibernateProperties());
      return emfb;
  }
  
  @Bean
  public JpaTransactionManager transactionManager(){
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
      return transactionManager;
  }
  
  private Properties getHibernateProperties(){
      Properties properties = new Properties();
      properties.put(PROP_HIBERNATE_DIALECT, env.getRequiredProperty(PROP_HIBERNATE_DIALECT));
      properties.put(PROP_HIBERNATE_SHOW_SQL, env.getRequiredProperty(PROP_HIBERNATE_SHOW_SQL));
      properties.put(PROP_HIBERNATE_HBM2DDL_AUTO, env.getRequiredProperty(PROP_HIBERNATE_HBM2DDL_AUTO));
      return properties;
  }
  </code></pre>