title: Spring not able to autowire repository in Controller
body: <p>I am new to Spring and was trying to get a simple webapp up and running using Spring Data and Spring MVC.</p>
  
  <p>Here is my Controller:</p>
  
  <pre><code>package org.springbyexample.web.servlet.mvc;
  
  @Controller
  @EnableJpaRepositories
  public class PersonController {
  
      @Autowired
      private UserRepository userRepository;
  
      public UserRepository getRepository() {
          return userRepository;
      }
  
      public void setUserRepository(UserRepository userRepository) {
          this.userRepository = userRepository;
      }
  
      // code removed
   }
  </code></pre>
  
  <p>Here is my repository:</p>
  
  <pre><code>package org.springbyexample.web.orm.repository;
  
  @Repository
  public interface UserRepository extends JpaRepository&lt;Users, String&gt; {
  
      Users findByUsername(String username);
  
  }
  </code></pre>
  
  <p>Here is my webmvc-context.xml</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"
     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
     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
                         http://www.springframework.org/schema/mvc
                         http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"&gt;
  
  &lt;context:component-scan base-package="org.springbyexample.web.servlet.mvc" /&gt;
  &lt;context:component-scan base-package="org.springbyexample.web.security" /&gt;
  
  &lt;jpa:repositories base-package="org.springbyexample.web.orm org.springbyexample.web.beans" entity-manager-factory-ref="emf"/&gt;
  
  &lt;mvc:annotation-driven /&gt;
  
  &lt;mvc:view-controller path="/index.html" /&gt;
  
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost/demodb" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="packagesToScan" value="org.springbyexample.web.orm" /&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="jpaProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;property name="persistenceProvider"&gt;
          &lt;bean class="org.hibernate.jpa.HibernatePersistenceProvider"&gt;&lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>On running this using maven-jetty-plugin, I get the following error:</p>
  
  <pre><code>2015-04-02 16:08:39.272:WARN::Nested in    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springbyexample.web.orm.repository.UserRepository org.springbyexample.web.servlet.mvc.PersonController.userRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springbyexample.web.orm.repository.UserRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}:
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springbyexample.web.orm.repository.UserRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1308)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1054)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
  </code></pre>
  
  <p>This is my User entity:</p>
  
  <pre><code>package org.springbyexample.web.beans;
  
  @Entity
  public class Users {
  
     private Timestamp activationDate;
     private Timestamp registrationDate;
     private int isActive;
     private String role;
     private String email;
     private int userId;
     @Id
     private String username;
     private String password;
     private String fullname;
     private String tranauth;
     private String clientPIN;
  
     // Getters and Setters for all of them
  </code></pre>
  
  <p>}</p>
  
  <p>Appreciate any help.</p>