title: can't create a new table with spring boot jpa
body: <p>After read the demo in <a href="http://spring.io" rel="nofollow noreferrer">spring.io</a>I try to write a demo for spring boot jpa of my own.But when I ran the demo it has these problem.It said <strong>Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class com.example.model.Person</strong>.And here is the detail. I had made some changes, but I still have this problem.</p>
  
  <pre><code>17:55:40.430 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
  17:55:40.432 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
  17:55:40.432 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/E:/workspace-sts-3.8.4.RELEASE/demo/target/classes/]
  
    .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v1.5.6.RELEASE)
  
  2017-08-09 17:55:40.645  INFO 10472 --- [  restartedMain] com.example.demo.DemoApplication         : Starting DemoApplication on MoriatyC with PID 10472 (E:\workspace-sts-3.8.4.RELEASE\demo\target\classes started by cmh in E:\workspace-sts-3.8.4.RELEASE\demo)
  2017-08-09 17:55:40.645  INFO 10472 --- [  restartedMain] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
  2017-08-09 17:55:40.828  INFO 10472 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@617bc958: startup date [Wed Aug 09 17:55:40 CST 2017]; root of context hierarchy
  2017-08-09 17:55:42.196  INFO 10472 --- [  restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
  2017-08-09 17:55:42.208  INFO 10472 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2017-08-09 17:55:42.208  INFO 10472 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.16
  2017-08-09 17:55:42.299  INFO 10472 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2017-08-09 17:55:42.299  INFO 10472 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1474 ms
  2017-08-09 17:55:42.433  INFO 10472 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
  2017-08-09 17:55:42.437  INFO 10472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
  2017-08-09 17:55:42.438  INFO 10472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
  2017-08-09 17:55:42.438  INFO 10472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
  2017-08-09 17:55:42.438  INFO 10472 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
  2017-08-09 17:55:42.884  INFO 10472 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
  2017-08-09 17:55:42.898  INFO 10472 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
      name: default
      ...]
  2017-08-09 17:55:42.950  INFO 10472 --- [  restartedMain] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
  2017-08-09 17:55:42.951  INFO 10472 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
  2017-08-09 17:55:42.952  INFO 10472 --- [  restartedMain] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
  2017-08-09 17:55:43.045  INFO 10472 --- [  restartedMain] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
  2017-08-09 17:55:43.126  INFO 10472 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
  2017-08-09 17:55:43.259  INFO 10472 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
  2017-08-09 17:55:43.264  INFO 10472 --- [  restartedMain] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete
  2017-08-09 17:55:43.288  INFO 10472 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  2017-08-09 17:55:43.301  WARN 10472 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'searchController': Unsatisfied dependency expressed through field 'personRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.dao.PersonRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  2017-08-09 17:55:43.302  INFO 10472 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
  2017-08-09 17:55:43.307  INFO 10472 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
  2017-08-09 17:55:43.317  INFO 10472 --- [  restartedMain] utoConfigurationReportLoggingInitializer : 
  
  Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2017-08-09 17:55:43.414 ERROR 10472 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field personRepository in com.example.controller.SearchController required a bean of type 'com.example.dao.PersonRepository' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'com.example.dao.PersonRepository' in your configuration.
  </code></pre>
  
  <p>And here is the <strong>PersonRepository.java</strong></p>
  
  <pre><code>package com.example.dao;
  
  import java.util.List;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.data.repository.query.Param;
  
  import com.example.model.Person;
  
  public interface PersonRepository extends JpaRepository&lt;Person, Integer&gt; {
      List&lt;Person&gt; findByAddress(String address);
      Person findByNameAndAddress(String name, String address);
      @Query("select p from Person p where p.name = :name and p.address=:address")
      Person withNameAndAddressQuery(@Param("name")String name, @Param("address")String address);
      Person withNameAndAddressNamedQuery(String name, String address);
  }
  </code></pre>
  
  <p><strong>Person.java</strong></p>
  
  <pre><code>package com.example.model;
  
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.NamedQuery;
  
  import lombok.AllArgsConstructor;
  import lombok.Data;
  import lombok.NoArgsConstructor;
  
  @Entity 
  @NoArgsConstructor
  @AllArgsConstructor
  @Data
  @NamedQuery(name="Person.withNameAndAddressNamedQuery", query = "select p from Person p where p.name=?1 and p.address=?2")
  public class Person {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
      private String name;
      private Integer age;
      private String address;
  }
  </code></pre>
  
  <p><strong>SearchController.java</strong></p>
  
  <pre><code>package com.example.controller;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.data.domain.Page;
  import org.springframework.data.domain.PageRequest;
  import org.springframework.data.domain.Sort;
  import org.springframework.data.domain.Sort.Direction;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.example.dao.PersonRepository;
  import com.example.model.Person;
  
  
  @RestController
  public class SearchController {
      @Autowired
      private PersonRepository personRepository;
  
      @RequestMapping("/save")
      public Person save(String name, String address, Integer age) {
          Person p = personRepository.save(new Person(null, name, age, address));
          return p;
      }
      @RequestMapping("/q1")
      public List&lt;Person&gt; q1(String address) {
          List&lt;Person&gt; people = personRepository.findByAddress(address);
          return people;
      }
      @RequestMapping("/q2")
      public Person q2(String name, String address) {
          Person people = personRepository.findByNameAndAddress(name, address);
          return people;
      }
      @RequestMapping("/q3")
      public Person q3(String name, String address) {
          Person people = personRepository.withNameAndAddressQuery(name, address);
          return people;
      }
      public Person q4(String name, String address) {
          Person p = personRepository.withNameAndAddressNamedQuery(name, address);
          return p;
      }
      @RequestMapping("/sort")
      public List&lt;Person&gt; sort() {
          List&lt;Person&gt; people = personRepository.findAll(new Sort(Direction.ASC,"age"));
          return people;
      }
      @RequestMapping("/page")
      public Page&lt;Person&gt; page() {
         Page&lt;Person&gt; pagePeople = personRepository.findAll(new PageRequest(1, 2));
         return pagePeople;
      }
  }
  </code></pre>
  
  <p>Here is the <strong>pom.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;demo&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;demo&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &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.5.6.RELEASE&lt;/version&gt;
          &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) --&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;!-- Use MySQL Connector-J --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&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;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.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;version&gt;1.16.10&lt;/version&gt;&lt;!--$NO-MVN-MAN-VER$ --&gt;
              &lt;!-- &lt;scope&gt;provided&lt;/scope&gt; --&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
  
              &lt;groupId&gt;net.sourceforge.nekohtml&lt;/groupId&gt;
              &lt;artifactId&gt;nekohtml&lt;/artifactId&gt;
              &lt;version&gt;1.9.22&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
              &lt;artifactId&gt;guava&lt;/artifactId&gt;
              &lt;version&gt;18.0&lt;/version&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;/project&gt;
  </code></pre>
  
  <p>and this is the <strong>application.properties</strong></p>
  
  <pre><code>spring.thymeleaf.mode=LEGACYHTML5
  spring.jpa.hibernate.ddl-auto=create
  spring.datasource.url=jdbc:mysql://localhost:3306/db_example
  spring.datasource.username=root
  spring.datasource.password=root
  spring.jpa.show-sql=true
  spring.jackson.serialization.indent-output=true
  </code></pre>
  
  <p>Here is my <strong>Application.java</strong></p>
  
  <pre><code>package com.example.demo;
  
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.SpringBootApplication;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  
  
  @SpringBootApplication
  @ComponentScan(basePackages = "com.example")
  public class DemoApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
      }
  }
  </code></pre>