title: Spring Data JPA No qualifying bean of type ... found for dependency
body: <p>I have sample test program to test Spring Data JPA, but it seems like the repository doesn't get generated.</p>
  
  <p>My config:</p>
  
  <pre class="lang-xml prettyprint-override"><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:context="http://www.springframework.org/schema/context"
         xmlns:jee="http://www.springframework.org/schema/jee"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-4.0.xsd
              http://www.springframework.org/schema/jee
              http://www.springframework.org/schema/jee/spring-jee.xsd"&gt;
  
      &lt;import resource="securityConfig.xml" /&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="com.test"&gt;
          &lt;context:exclude-filter type="annotation"
                  expression="org.springframework.stereotype.Controller" /&gt;
      &lt;/context:component-scan&gt;
  
      &lt;jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/test"/&gt;
  
      &lt;bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="myDataSource" /&gt;
          &lt;property name="packagesToScan" value="com.test.security" /&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
          &lt;/property&gt;
          &lt;property name="jpaProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;create-drop&lt;/prop&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="myEmf" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>User entity:</p>
  
  <pre><code>package com.test.security;
  
  import org.springframework.security.core.CredentialsContainer;
  import org.springframework.security.core.userdetails.UserDetails;
  
  @Entity
  @Table
  public class UserPrincipal implements UserDetails, CredentialsContainer, Cloneable {
      private static final long serialVersionUID = 1L;
  
      private long id;
  ....
  }
  </code></pre>
  
  <p>UserRespository:</p>
  
  <pre><code>package com.test.security;
  
  import org.springframework.data.repository.CrudRepository;
  
  public interface UserRepository extends CrudRepository&lt;UserPrincipal, Long&gt;
  {
      UserPrincipal getByUsername(String username);
  }
  </code></pre>
  
  <p>UserService:</p>
  
  <pre><code>package com.test.security;
  
  @Service
  public class UserService implements UserDetailsService {
      @Inject
      UserRepository userRepository;
  
      @Override
      @Transactional
      public UserPrincipal loadUserByUsername(String username) {
          UserPrincipal principal = userRepository.getByUsername(username);
          // make sure the authorities and password are loaded
          principal.getAuthorities().size();
          principal.getPassword();
          return principal;
      }
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'org.springframework.security.filterChains':
    Cannot resolve reference to bean
    'org.springframework.security.web.DefaultSecurityFilterChain#0' while
    setting bean property 'sourceList' with key [0]; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.web.DefaultSecurityFilterChain#0':
    Cannot resolve reference to bean
    'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0'
    while setting constructor argument with key [3]; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0':
    Cannot resolve reference to bean
    'org.springframework.security.authentication.ProviderManager#0' while
    setting bean property 'authenticationManager'; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.authentication.ProviderManager#0':
    Cannot resolve reference to bean
    'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0'
    while setting constructor argument; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0':
    FactoryBean threw exception on object creation; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.authenticationManager': Cannot resolve
    reference to bean
    'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0'
    while setting constructor argument with key [0]; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name
    'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0':
    Cannot resolve reference to bean 'userService' while setting bean
    property 'userDetailsService'; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'userService': Injection of autowired
    dependencies failed; nested exception is
    org.springframework.beans.factory.BeanCreationException: Could not
    autowire field: com.test.security.UserRepository
    com.test.security.UserService.userRepository; nested exception is
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No
    qualifying bean of type [com.test.security.UserRepository] found for
    dependency: expected at least 1 bean which qualifies as autowire
    candidate for this dependency. Dependency annotations:
    {@javax.inject.Inject()}</p>
  </blockquote>