Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring引导:创建名为';org.springframework.boot.autoconfigure.orm.jpa.hibernatejpa自动配置_Spring_Spring Boot - Fatal编程技术网

spring引导:创建名为';org.springframework.boot.autoconfigure.orm.jpa.hibernatejpa自动配置

spring引导:创建名为';org.springframework.boot.autoconfigure.orm.jpa.hibernatejpa自动配置,spring,spring-boot,Spring,Spring Boot,我正在从以下链接开发Spring Boot示例:。pom.xml文件具有sqllite依赖项我将gradle项目转换为maven项目。当我简单地运行main方法时,我看到以下错误: 2016-12-27 12:37:59.457 DEBUG 16320 --- [ main] o.h.j.i.EntityManagerFactoryRegistry : Initializing EntityManagerFactoryRegistry : org.hibernate.

我正在从以下链接开发Spring Boot示例:。pom.xml文件具有sqllite依赖项我将gradle项目转换为maven项目。当我简单地运行main方法时,我看到以下错误:

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.
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>de.techdev.jaxenter</groupId>
    <artifactId>jaxenter-showcase-master</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>jaxenter-showcase-master</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

        <!-- <dependency> <groupId>org.xerial</groupId> <artifactId>sqlite-jdbc</artifactId> 
            <version>3.15.1</version> </dependency> -->

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.40</version>
        </dependency>


        <!-- 2. Bridge logging from JCL to SLF4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-release</id>
            <url>http://repo.spring.io/release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <url>http://repo.spring.io/snapshot</url>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <url>http://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>
</project>
PersonEventHandler.java

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {

}
@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
    }
}
@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));
    }
}
@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')");
    }
}
public interface PersonRepository extends JpaRepository<Person, Long>{

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    Page<Person> findAll(Pageable pageable);

    @PostAuthorize("returnObject.firstName == principal.username or hasRole('ROLE_ADMIN')")
    Person findOne(Long aLong);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    List<Person> findByFirstNameLike(@Param("firstName") String firstName);

    @RestResource(exported = false)
    Person findByFirstNameEquals(String firstName);
}
PersistenceConfiguration.java

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {

}
@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
    }
}
@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));
    }
}
@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')");
    }
}
public interface PersonRepository extends JpaRepository<Person, Long>{

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    Page<Person> findAll(Pageable pageable);

    @PostAuthorize("returnObject.firstName == principal.username or hasRole('ROLE_ADMIN')")
    Person findOne(Long aLong);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    List<Person> findByFirstNameLike(@Param("firstName") String firstName);

    @RestResource(exported = false)
    Person findByFirstNameEquals(String firstName);
}
OAuthConfiguration.java

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {

}
@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
    }
}
@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));
    }
}
@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')");
    }
}
public interface PersonRepository extends JpaRepository<Person, Long>{

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    Page<Person> findAll(Pageable pageable);

    @PostAuthorize("returnObject.firstName == principal.username or hasRole('ROLE_ADMIN')")
    Person findOne(Long aLong);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    List<Person> findByFirstNameLike(@Param("firstName") String firstName);

    @RestResource(exported = false)
    Person findByFirstNameEquals(String firstName);
}
PersonRepository.java

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration {

}
@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
    }
}
@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));
    }
}
@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')");
    }
}
public interface PersonRepository extends JpaRepository<Person, Long>{

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    Page<Person> findAll(Pageable pageable);

    @PostAuthorize("returnObject.firstName == principal.username or hasRole('ROLE_ADMIN')")
    Person findOne(Long aLong);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    List<Person> findByFirstNameLike(@Param("firstName") String firstName);

    @RestResource(exported = false)
    Person findByFirstNameEquals(String firstName);
}

删除
@EnableJpaRepositories
。SpringBoot会在
@SpringBootApplication
所在的包中自动为您执行此操作。只要你的存储库在这个包中(或者是一个子包),它们就会被找到。Thnx,现在我又遇到了一个错误,你的数据库可能是空的。请阅读并避免在同一线程中混合问题。删除
@EnableJpaRepositories
。SpringBoot会在
@SpringBootApplication
所在的包中自动为您执行此操作。只要你的存储库在这个包中(或者是一个子包),它们就会被找到。Thnx,现在我又遇到了一个错误,你的数据库可能是空的。请阅读,避免在同一个线程中混合问题。