title: Java Spring JPA Repository
body: <p>I'm a Spring noob and I'm struggling with it.</p>
  
  <p>Basically before starting develop my Server with Spring in conjunction with JPA I tried to start a simple example just to get used to this framework.
  I've already get succeded in make Spring working with some frameworks as Log4J, Swagger and others. Now I'm trying to work with JPA and there are some points i can find out the solution.</p>
  
  <p>I saw some blogs on how to develop with it and from all thousands options i choose to create my Repository Interfece and <code>extend Repository&lt;T, ID&gt;</code>. You can see my code bellow:</p>
  
  <pre><code>package com.example.model;
  @Entity
  public class Person {
  
      @Id
      public Integer id;
  
      public String name;
  
      public Person(){}
  }
  
  package com.example.repository;
  public interface PersonRepository extends Repository&lt;Person, Integer&gt; {
      Collection&lt;Person&gt; findAll();
  }
  
  
  package com.example.controller;
  @RestController
  public class PersonController {
  
      @Autowired
      private PersonRepository repo;
  
      @RequestMapping(value = "/persons", method = RequestMethod.GET)
      public Collection&lt;Person&gt; getAll() {
          return repo.findAll();
      }
  }
  
  package com.example;
  @SpringBootApplication
  public class App {
      public static void main(String[] args) {
          SpringApplication.run(App.class, args);
      }
  }
  </code></pre>
  
  <p>And I also have the application.properties file:</p>
  
  <pre><code>spring.datasource.platform=postgres
  spring.datasource.url=jdbc:postgresql://localhost:5432/test_db
  spring.datasource.username=test
  spring.datasource.password=test
  spring.datasource.driver-class-name=org.postgresql.Driver
  </code></pre>
  
  <p>When I put the server running I get the following exception: </p>
  
  <pre><code>: Exception encountered during context initialization - cancelling refresh attempt: 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 com.example.repository.PersonRepository com.example.controllers.PersonController.repo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.repository.PersonRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 
  : Closing JPA EntityManagerFactory for persistence unit 'default'
  : Stopping service Tomcat
  : Application startup failed
  
  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 com.example.repository.PersonRepository com.example.controllers.PersonController.repo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.example.repository.PersonRepository] 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)}
  </code></pre>
  
  <p>I created a Github Repository to share the code <a href="https://github.com/BrunoMNDantas/SpringJPA" rel="nofollow">here</a>.</p>
  
  <p>Any clue about what am I doing wrong?</p>