title: Spring MVC + Spring Data, error when inject a Repository on Service
body: <p>I'm get the follow errors, when i try to inject with @Autowired annotation a Repository interface (extends CrudRepository) on a Service (@Service), in a project using Spring MVC + Spring Data + MariaDB:</p>
  
  <pre class="lang-java prettyprint-override"><code>GRAVE: StandardWrapper.Throwable
  org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pessoaController': Unsatisfied dependency expressed through field 'pessoaService': Error creating bean with name 'pessoaService': Unsatisfied dependency expressed through field 'pessoaRepository': No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pessoaService': Unsatisfied dependency expressed through field 'pessoaRepository': No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: 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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
  at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
  at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
  at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
  at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
  at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
  at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
  at javax.servlet.GenericServlet.init(GenericServlet.java:158)
  at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
  at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
  at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4914)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5201)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3746)
  at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:292)
  at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5528)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)
  at java.lang.Thread.run(Thread.java:745)
  
  Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pessoaService': Unsatisfied dependency expressed through field 'pessoaRepository': No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: 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.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:187)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1208)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1048)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570)
  ... 33 more
  
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: 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:1398)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570)
  ... 47 more
  
  GRAVE: Servlet [appServlet] in web application [/adi] threw load() exception
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [br.com.coderi.adi.repository.PessoaRepository] found for dependency [br.com.coderi.adi.repository.PessoaRepository]: 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:1398)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570)
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:187)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1208)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1048)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570)
  at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
  at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
  at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
  at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
  at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
  at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
  at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
  at javax.servlet.GenericServlet.init(GenericServlet.java:158)
  at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
  at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
  at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4914)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5201)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3746)
  at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:292)
  at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5528)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
  at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <hr>
  
  <p>This is my <strong>Model</strong>:
  </p>
  
  <pre><code>package br.com.coderi.adi.model;
  
  import java.util.Date;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.validation.constraints.NotNull;
  
  @Entity
  public class Pessoa {
  
      @Id
      @GeneratedValue
      private Integer id;
  
      @NotNull
      private String nome;
  
      @NotNull
      private String sobrenome;
  
      private String rg;
  
      private String cps;
  
  &lt;!-- Get/Setters methods... --&gt;
  }
  </code></pre>
  
  <p>This is my <strong>Controller</strong>:
  </p>
  
  <pre><code>package br.com.coderi.adi.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  import br.com.coderi.adi.service.PessoaService;
  
  @Controller
  @RequestMapping("/pessoa")
  public class PessoaController {
  
  @Autowired
  private PessoaService pessoaService;
  
      @RequestMapping("/listar")
      public String listar(Model model) {
          model.addAttribute("pessoas", pessoaService.getPessoas());
          return "atendente/pessoa/listar";
      }
  
      @RequestMapping(value = "/cadastrar", method = RequestMethod.GET)
      public String cadastrar() {
          return "atendente/pessoa/cadastrar";
      }
  }
  </code></pre>
  
  <p>This is my <strong>Repository</strong>:
  </p>
  
  <pre><code>package br.com.coderi.adi.repository;
  
  import org.springframework.data.repository.CrudRepository;
  import org.springframework.stereotype.Repository;
  
  import br.com.coderi.adi.model.Pessoa;
  
  @Repository
  public interface PessoaRepository extends CrudRepository&lt;Pessoa, Integer&gt; {
  
  }
  </code></pre>
  
  <p>This is my <strong>Service</strong>:
  </p>
  
  <pre><code>package br.com.coderi.adi.service;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import br.com.coderi.adi.model.Pessoa;
  import br.com.coderi.adi.repository.PessoaRepository;
  
  @Service
  public class PessoaService {
  
      @Autowired
      private PessoaRepository pessoaRepository;
  
      public Iterable&lt;Pessoa&gt; getPessoas() {
          pessoaRepository.findAll();
          return null;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>The <strong>servlet-context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
  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
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
  &lt;!-- DispatcherServlet Context: defines servlet's request-processing infrastructure --&gt;
  &lt;context:component-scan base-package="br.com.coderi.adi"&gt;&lt;/context:component-scan&gt;
  
  
  &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
  &lt;annotation-driven&gt;&lt;/annotation-driven&gt;
  &lt;context:annotation-config&gt;&lt;/context:annotation-config&gt;
  &lt;default-servlet-handler /&gt;
  
  
  &lt;!-- Handles HTTP GET requests for /resources/ by efficiently serving up static resources in the webapp/resources directory --&gt;
  &lt;resources location="/resources/" mapping="/resources/**"&gt;&lt;/resources&gt;
  
  
  &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt;
  &lt;beans:bean
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
  &lt;/beans:bean&gt;
  
  
  &lt;!-- Message source --&gt;
  &lt;beans:bean id="messageSource"
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
      &lt;beans:property name="basename" value="/WEB-INF/messages" /&gt;
  &lt;/beans:bean&gt;
  
  
  &lt;!-- Data Sources --&gt;
  &lt;beans:bean id="mariadbDataSource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;beans:property name="driverClassName" value="org.mariadb.jdbc.Driver" /&gt;
      &lt;beans:property name="url"
          value="jdbc:mariadb://localhost:3306/coderi_adi?useSSL=false" /&gt;
      &lt;beans:property name="username" value="root" /&gt;
      &lt;beans:property name="password" value="" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;beans:property name="dataSource" ref="mariadbDataSource" /&gt;
      &lt;beans:property name="persistenceUnitName" value="adiPersistenceUnit" /&gt;
      &lt;beans:property name="jpaVendorAdapter"&gt;
          &lt;beans:bean
              class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="transactionManager"
      class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;beans:property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Ps: I used the same architecture on a project using the "Spring Boot" and had worked well.<br>
  I do not understand: [...] expected at least 1 bean which qualifies as autowire candidate for this dependency.</p>