title: spring boot : Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
body: <p>I am developing <strong>Spring Boot</strong> example from the link: <a href="https://jaxenter.com/rest-api-spring-java-8-112289.html" rel="nofollow noreferrer">https://jaxenter.com/rest-api-spring-java-8-112289.html</a>. The pom.xml file has sqllite dependencies. <strong>I converted gradle project to maven project</strong>. When I simply run my main method, I see the below error:</p>
  
  <pre><code>2016-12-27 12:37:59.457 DEBUG 16320 --- [           main] o.h.j.i.EntityManagerFactoryRegistry     : Initializing EntityManagerFactoryRegistry : org.hibernate.jpa.internal.EntityManagerFactoryRegistry@2ad8e1
  2016-12-27 12:37:59.457 DEBUG 16320 --- [           main] o.h.j.i.EntityManagerFactoryRegistry     : Registering EntityManagerFactory: default 
  2016-12-27 12:37:59.457  INFO 16320 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  2016-12-27 12:37:59.535  WARN 16320 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'persistenceConfiguration': Unsatisfied dependency expressed through field 'personRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'de.techdev.jaxenter.repository.PersonRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  2016-12-27 12:37:59.535  INFO 16320 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
  2016-12-27 12:37:59.535 DEBUG 16320 --- [           main] o.hibernate.internal.SessionFactoryImpl  : HHH000031: Closing
  2016-12-27 12:37:59.535 DEBUG 16320 --- [           main] o.h.s.i.AbstractServiceRegistryImpl      : Implicitly destroying ServiceRegistry on de-registration of all child ServiceRegistries
  2016-12-27 12:37:59.535 DEBUG 16320 --- [           main] o.h.b.r.i.BootstrapServiceRegistryImpl   : Implicitly destroying Boot-strap registry on de-registration of all child ServiceRegistries
  2016-12-27 12:37:59.535 DEBUG 16320 --- [           main] o.h.j.i.EntityManagerFactoryRegistry     : Remove: name=default
  2016-12-27 12:37:59.535  INFO 16320 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
  2016-12-27 12:37:59.551  WARN 16320 --- [           main] o.s.boot.SpringApplication               : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor': Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.RuntimeException: Could not postProcess org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@108c060 of type class org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler)
  2016-12-27 12:37:59.847 ERROR 16320 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 
  
  ***************************
  APPLICATION FAILED TO START
  ***************************
  
  Description:
  
  Field personRepository in de.techdev.jaxenter.config.PersistenceConfiguration required a bean of type 'de.techdev.jaxenter.repository.PersonRepository' that could not be found.
  
  
  Action:
  
  Consider defining a bean of type 'de.techdev.jaxenter.repository.PersonRepository' in your configuration.
  </code></pre>
  
  <p><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;de.techdev.jaxenter&lt;/groupId&gt;
      &lt;artifactId&gt;jaxenter-showcase-master&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;jaxenter-showcase-master&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.4.3.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.7&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&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-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-data-rest&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security.oauth&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-oauth2&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;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;!-- &lt;dependency&gt; &lt;groupId&gt;org.xerial&lt;/groupId&gt; &lt;artifactId&gt;sqlite-jdbc&lt;/artifactId&gt; 
              &lt;version&gt;3.15.1&lt;/version&gt; &lt;/dependency&gt; --&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.40&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- 2. Bridge logging from JCL to SLF4j --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;jcl-over-slf4j&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
              &lt;artifactId&gt;logback-classic&lt;/artifactId&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.scala-lang&lt;/groupId&gt;
              &lt;artifactId&gt;scala-library&lt;/artifactId&gt;
              &lt;version&gt;2.11.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;repositories&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-release&lt;/id&gt;
              &lt;url&gt;http://repo.spring.io/release&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;false&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt;
          &lt;repository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;url&gt;http://repo.spring.io/milestone&lt;/url&gt;
              &lt;snapshots&gt;
                  &lt;enabled&gt;true&lt;/enabled&gt;
              &lt;/snapshots&gt;
          &lt;/repository&gt;
      &lt;/repositories&gt;
      &lt;pluginRepositories&gt;
          &lt;pluginRepository&gt;
              &lt;id&gt;spring-snapshots&lt;/id&gt;
              &lt;url&gt;http://repo.spring.io/snapshot&lt;/url&gt;
          &lt;/pluginRepository&gt;
          &lt;pluginRepository&gt;
              &lt;id&gt;spring-milestones&lt;/id&gt;
              &lt;url&gt;http://repo.spring.io/milestone&lt;/url&gt;
          &lt;/pluginRepository&gt;
      &lt;/pluginRepositories&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>application.properties</strong></p>
  
  <p>oauth_db=jdbc:sqlite:tokens.db</p>
  
  <p><a href="https://i.stack.imgur.com/iGgp1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iGgp1.png" alt="enter image description here"></a></p>
  
  <p><strong>SecurityConfiguration.java</strong></p>
  
  <pre><code>@Configuration
  @EnableGlobalMethodSecurity(prePostEnabled = true)
  public class SecurityConfiguration {
  
  }
  </code></pre>
  
  <p><strong>PersonEventHandler.java</strong></p>
  
  <pre><code>@Component
  @RepositoryEventHandler(Person.class)
  public class PersonEventHandler {
  
      @PreAuthorize("hasRole('ROLE_ADMIN')")
      @HandleBeforeSave
      public void checkPUTAuthority(Person person) {
          // only security check
      }
  
      @PreAuthorize("hasRole('ROLE_ADMIN')")
      @HandleBeforeCreate
      public void checkPOSTAuthority(Person person) {
          // only security check
      }
  
      @PreAuthorize("hasRole('ROLE_ADMIN')")
      @HandleBeforeDelete
      public void checkDELETEAuthority(Person person) {
          // only security check
      }
  }
  </code></pre>
  
  <p><strong>PersistenceConfiguration.java</strong></p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories
  public class PersistenceConfiguration {
  
      @Autowired
      private PersonRepository personRepository;
  
      @PostConstruct
      private void addPersons() {
          Person john = new Person();
          john.setFirstName("John");
  
          Person mary = new Person();
          mary.setFirstName("Mary");
  
          personRepository.save(Arrays.asList(john, mary));
      }
  }
  </code></pre>
  
  <p><strong>OAuthConfiguration.java</strong></p>
  
  <pre><code>@Configuration
  @EnableResourceServer
  public class OAuthConfiguration extends ResourceServerConfigurerAdapter{
  
      @Value("${oauth_db}")
      private String oauthDbJdbc;
  
      @Bean
      public TokenStore tokenStore(){
          DataSource dataSource = DataSourceBuilder.create().driverClassName("org.sqlite.JDBC").url(oauthDbJdbc).build();
          return new JdbcTokenStore(dataSource);
      }
  
      @Override
      public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
          resources.resourceId("jaxenter")
          .tokenStore(tokenStore());
      }
  
      @Override
      public void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
              .antMatchers(HttpMethod.GET, "/**").access("#oauth2.hasScope('read')")
              .antMatchers(HttpMethod.OPTIONS, "/**").access("#oauth2.hasScope('read')")
              .antMatchers(HttpMethod.POST, "/**").access("#oauth2.hasScope('write')")
              .antMatchers(HttpMethod.PUT, "/**").access("#oauth2.hasScope('write')")
              .antMatchers(HttpMethod.PATCH, "/**").access("#oauth2.hasScope('write')")
              .antMatchers(HttpMethod.DELETE, "/**").access("#oauth2.hasScope('write')");
      }
  }
  </code></pre>
  
  <p><strong>PersonRepository.java</strong></p>
  
  <pre><code>public interface PersonRepository extends JpaRepository&lt;Person, Long&gt;{
  
      @PreAuthorize("hasRole('ROLE_ADMIN')")
      Page&lt;Person&gt; findAll(Pageable pageable);
  
      @PostAuthorize("returnObject.firstName == principal.username or hasRole('ROLE_ADMIN')")
      Person findOne(Long aLong);
  
      @PreAuthorize("hasRole('ROLE_ADMIN')")
      List&lt;Person&gt; findByFirstNameLike(@Param("firstName") String firstName);
  
      @RestResource(exported = false)
      Person findByFirstNameEquals(String firstName);
  }
  </code></pre>
  
  <p><strong>EDIT-1:</strong></p>
  
  <pre><code>2016-12-27 14:11:39.429  WARN 11548 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1364, SQLState: HY000
  2016-12-27 14:11:39.429 ERROR 11548 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : Field 'email' doesn't have a default value
  2016-12-27 14:11:39.429 DEBUG 11548 --- [           main] o.h.jpa.spi.AbstractEntityManagerImpl    : Mark transaction for rollback
  2016-12-27 14:11:39.445 DEBUG 11548 --- [           main] o.h.e.t.internal.TransactionImpl         : rolling back
  2016-12-27 14:11:39.445  WARN 11548 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceConfiguration': Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
  2016-12-27 14:11:39.445  INFO 11548 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
  2016-12-27 14:11:39.445 DEBUG 11548 --- [           main] o.hibernate.internal.SessionFactoryImpl  : HHH000031: Closing
  2016-12-27 14:11:39.445 DEBUG 11548 --- [           main] o.h.s.i.AbstractServiceRegistryImpl      : Implicitly destroying ServiceRegistry on de-registration of all child ServiceRegistries
  2016-12-27 14:11:39.445 DEBUG 11548 --- [           main] o.h.b.r.i.BootstrapServiceRegistryImpl   : Implicitly destroying Boot-strap registry on de-registration of all child ServiceRegistries
  2016-12-27 14:11:39.445 DEBUG 11548 --- [           main] o.h.j.i.EntityManagerFactoryRegistry     : Remove: name=default
  2016-12-27 14:11:39.445  INFO 11548 --- [           main] o.apache.catalina.core.StandardService   : Stopping service Tomcat
  2016-12-27 14:11:39.460  INFO 11548 --- [           main] utoConfigurationReportLoggingInitializer : 
  
  Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  2016-12-27 14:11:39.460 ERROR 11548 --- [           main] o.s.boot.SpringApplication               : Application startup failed
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistenceConfiguration': Invocation of init method failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
      at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:137)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1581)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
      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:759)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
  </code></pre>