title: Spring - CrudRepository is not created
body: <p>The <code>CrudRepository</code> bean</p>
  
  <pre><code>@Repository
  public interface UserDao extends CrudRepository&lt;User, Long&gt;
  {
      List&lt;User&gt; findByFirstNameAndLastName(String firstName, String lastName);
  } 
  </code></pre>
  
  <p>for the <code>User</code> resource</p>
  
  <pre><code>@Entity
  @Table(name="User")
  public class User 
  {
      @Id
      @GeneratedValue
      private long id;
  
      @Column(name="first_name")
      private String firstName;
  
      @Column(name="last_name")
      private String lastName;
  
      /* --- Getters,setters,default constructor -------*/
  }
  </code></pre>
  
  <p>is not created when I start my Spring boot app</p>
  
  <pre><code>Field dao in base.package.service.UserService required a bean 
  of type 'base.package.dao.UserDao' that could not be found.
  </code></pre>
  
  <p>but the packages are definitely scanned</p>
  
  <pre><code>@SpringBootApplication(scanBasePackages= {"base.package"})
  </code></pre>
  
  <p>I got the strong suspicion that it has to do something with the embedded database <code>h2</code> that I am using. I am trying to create the <code>User</code> table in <code>schema.sql</code></p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS User (
      id   INTEGER      NOT NULL AUTO_INCREMENT,
      first_name VARCHAR(128) NOT NULL,
      last_name VARCHAR(128) NOT NULL,
      PRIMARY KEY (id)
  );
  </code></pre>
  
  <p>but as soon as I uncomment <code>IF NOT EXISTS</code> it throws an error (table already exists). So this firstly means that spring takes charge of created the schema. But I get the feeling that the table is not recreated because in the <code>data.sql</code> script </p>
  
  <pre><code>INSERT INTO User (id,first_name,last_name) VALUES (1,'Vincent', 'Vega');
  </code></pre>
  
  <p>I always have to manually increment the <code>id</code> on startup otherwise i get a </p>
  
  <pre><code>org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.USER(ID)"
  </code></pre>
  
  <p>Here are the jpa properties from <code>application.properties</code></p>
  
  <pre><code># below properties create schema, so schema.sql is redundant
  spring.jpa.generate-ddl=true  
  spring.jpa.hibernate.ddl-auto=create-drop
  spring.datasource.initialization-mode=always
  spring.jpa.database=H2
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  spring.jpa.show-sql=true
  spring.datasource.driverClassName=org.h2.Driver
  spring.datasource.url=jdbc:h2:~/testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE
  
  
  spring.datasource.name=testdb
  spring.h2.console.enabled=true
  spring.h2.console.path=/h2-console
  </code></pre>
  
  <p>The reason why I think that the table is never recreated on startup is because I get this error when the app closes</p>
  
  <pre><code>2018-02-02 09:27:47.907 INFO  [restartedMain] [StandardService] Stopping service [Tomcat]
  2018-02-02 09:27:47.907 WARN  [localhost-startStop-1] [WebappClassLoaderBase] The web application [ROOT] appears to have started a thread named [MVStore background writer nio:C:/Users/user/testdb.mv.db] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
   java.lang.Object.wait(Native Method)
  </code></pre>
  
  <p>This is followed by the exception that <code>UserDao</code> bean is not created.</p>
  
  <pre><code>***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field dao in base.package.user.service.UserService required a bean of type 'base.package.user.dao.UserDao' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'base.package.user.dao.UserDao' in your configuration.
  </code></pre>
  
  <p><strong>POM.XML</strong></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;2.0.0.M7&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;spring-cloud.version&gt;Finchley.M5&lt;/spring-cloud.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-starter-config&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-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&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;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
          &lt;/dependency&gt;
         /* .... */
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is the <code>UserService</code></p>
  
  <pre><code>@Service
  public class UserService 
  {
      @Autowired private UserDao dao;
  
      public List&lt;User&gt; findByFirstNameAndLastName(String firstName, String lastName)
      {
          return dao.findByFirstNameAndLastName(firstName, lastName);
      }
  
      public User save(final User user)
      {
          return dao.save(user);
      }
  }
  </code></pre>
  
  <p><strong>EDIT 2</strong> </p>
  
  <p>Now I am getting</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.project.bot.user.User
      at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:472)
      at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.&lt;init&gt;(JpaMetamodelEntityInformation.java:72)
      at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)
      at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:169)
      at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:107)
      at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:90)
      at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:300)
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$3(RepositoryFactoryBeanSupport.java:287)
      at org.springframework.data.util.Lazy.getNullable(Lazy.java:141)
      at org.springframework.data.util.Lazy.get(Lazy.java:63)
      at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:290)
      at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:102)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)
      ... 102 common frames omitted
  </code></pre>