title: Spring Boot `org.springframework.beans.factory.BeanCreationException: Error creating bean Injection of autowired dependencies failed;
body: <p>I am a Spring Boot newbie and I have a simple application which has a controller and a Thymeleaf template. </p>
  
  <p>When the application starts, in order to see if everything is working, a Spring <code>ApplicationListener</code> called <code>RepoTester</code> should run to check the methods of a service class. The service class calls methods of the <code>PersonRepository</code> which simply extends Spring's <code>CrudRepository</code>. But every time I go to try running the application, it falls over giving me the message:</p>
  
  <p><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'repoTester': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private webapps.city2016.micro.code.service.PersonService webapps.city2016.micro.code.bootstrap.RepoTester.personService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private webapps.city2016.micro.code.repo.PersonRepository webapps.city2016.micro.code.service.PersonServiceImpl.personRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [webapps.city2016.micro.code.repo.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></p>
  
  <p>But I cannot see why.</p>
  
  <p>The <code>ApplicationListener</code> class is simply:</p>
  
  <pre><code>@Component
  public class RepoTester implements ApplicationListener&lt;ContextRefreshedEvent&gt; {
  
  @Autowired
  private PersonService personService;
  
  private static final Logger logger = Logger.getLogger(RepoTester.class);   
  
  @Override
  public void onApplicationEvent(ContextRefreshedEvent event) {
      logger.info(RepoTester.class.getName() + ".onApplicationEvent() method called."); 
  
      // Create Person.
      Person person = new Person();
      person.setName("Cleo Markham");
      person.setAddress("48 Alysbury Road");
      person.setTelephone("34561287");
      person.setEmail("c.laithwaite@collosus.net");
      person = personService.save(person);        
  </code></pre>
  
  <p>The <code>Person</code> class is simply: </p>
  
  <pre><code>public class Person {
  
      // Attributes.    
      private Integer personId;
      private String name;
      private String address;
      private String telephone;
      private String email;
  </code></pre>
  
  <p>With <code>getter</code> and <code>setter</code> methods for each attribute.</p>
  
  <p>The application also has a properties file called <code>application.properties</code> specifying the Derby database to use: </p>
  
  <pre><code>spring.datasource.driverClassName=org.apache.derby.jdbc.ClientDriver
  spring.datasource.url=jdbc:derby://localhost:1527/Library
  spring.datasource.username=username
  spring.datasource.password=password
  </code></pre>
  
  <p>The code of the service class is simply:</p>
  
  <pre><code>@Service()
  public class PersonServiceImpl implements PersonService {
  
      @Autowired
      private PersonRepository personRepository;
  
      private static final Logger logger = Logger.getLogger(PersonServiceImpl.class);   
  
      public PersonServiceImpl() {
      }
  
      @Override
      public void delete(Integer personId) {
          logger.info(PersonServiceImpl.class.getName() + ".delete() method called."); 
  
          personRepository.delete(personId);
      }
  
      @Override
      public boolean exists(Integer personId) {
          logger.info(PersonServiceImpl.class.getName() + ".exists() method called."); 
  
          return personRepository.exists(personId);
      }
  
      @Override
      public Person findOne(Integer personId) {
          logger.info(PersonServiceImpl.class.getName() + ".findOne() method called."); 
  
          return personRepository.findOne(personId);
      }
  
      @Override
      public Iterable&lt;Person&gt; findAll() {
          logger.info(PersonServiceImpl.class.getName() + ".findAll() method called."); 
  
          return personRepository.findAll();
      }
  
      @Override
      public Person save(Person person) {
          logger.info(PersonServiceImpl.class.getName() + ".save() method called."); 
  
          return personRepository.save(person);
      }    
  </code></pre>
  
  <p>And the repository is:</p>
  
  <pre><code>package webapps.city2016.micro.code.repo;
  
  import org.springframework.data.repository.CrudRepository;
  
  import webapps.city2016.micro.code.model.Person;
  
  public interface PersonRepository extends CrudRepository&lt;Person, Integer&gt; {
  } 
  </code></pre>
  
  <p>My Maven file is:</p>
  
  <p>
  http://maven.apache.org/xsd/maven-4.0.0.xsd">
      4.0.0
      webapps.city2016.micro
      RegistrationSpringBootThymeleaf1
      1.0-SNAPSHOT
      jar<br>
      
          UTF-8
          1.8
          1.8
      </p>
  
  <pre><code>&lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.3.5.RELEASE&lt;/version&gt;
      &lt;relativePath /&gt;
  &lt;/parent&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
          &lt;artifactId&gt;derbyclient&lt;/artifactId&gt;
          &lt;version&gt;10.12.1.1&lt;/version&gt;
      &lt;/dependency&gt;      
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
      &lt;/dependency&gt;  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
      &lt;/dependency&gt;                    
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  
  &lt;name&gt;RegistrationSpringBootThymeleaf1&lt;/name&gt;
  </code></pre>
  
  <p></p>
  
  <p>Can anyone advise where I am wrong?</p>