【问题标题】:Spring Boot + JPA + Hibernate - BeanCreationExceptionSpring Boot + JPA + Hibernate - BeanCreationException
【发布时间】:2016-01-12 16:51:13
【问题描述】:

我目前正在使用 Spring Boot 在 Vaadin 开发一个项目,我想重用另一个项目中的一些存储库,而不将该项目添加为依赖项,但是当我尝试运行该项目时,我收到此错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataCache': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.myproject.vas.aftersales.repository.AfterSalesFileRepository com.myproject.vas.DataCache.afterSalesFileRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'afterSalesFileRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;

我已经在网上搜索了解决方案,并尝试了我能找到的一切,从切换包到将依赖版本更改为......

我的仓库:

@Component
public interface AfterSalesFileRepository extends JpaRepository<AfterSalesFile, Integer> {

    @Query("select m from AfterSalesFile m " +
            "where m.id=:id and m.status is not 'INACTIVE'")
    AfterSalesFile findOne(@Param("id") final Integer id);
}

尝试初始化和使用存储库的类:

@Component
public class DataCache {

    @Getter(AccessLevel.PRIVATE)
    private CustomerIdentityRepository customerIdentityRepository;

    @Autowired
    private AfterSalesFileRepository afterSalesFileRepository;

    @Autowired
    public DataCache(CustomerIdentityRepository customerIdentityRepository) {
        this.customerIdentityRepository = customerIdentityRepository;

    }

...

    public List<AfterSalesFile> getAllAftersales() {
        return afterSalesFileRepository.findAll();
    }
}

我的数据库配置:

@Configuration
public class DatabaseConfiguration implements EnvironmentAware {

    private RelaxedPropertyResolver jpaPropertyResolver;
    @Autowired(required = false)
    private PersistenceUnitManager persistenceUnitManager;

    @Override
    public void setEnvironment(Environment environment) {
        this.jpaPropertyResolver = new RelaxedPropertyResolver(environment, "spring.jpa.");
    }

    @Bean
    @DependsOn("jdbcTemplate")
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
        LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
        if (persistenceUnitManager != null) {
            entityManagerFactoryBean
                    .setPersistenceUnitManager(persistenceUnitManager);
        }
        entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
        entityManagerFactoryBean.setDataSource(dataSource);
        entityManagerFactoryBean.setPackagesToScan("com.myproject.vas.aftersales");
        entityManagerFactoryBean.getJpaPropertyMap().putAll(jpaPropertyResolver.getSubProperties("properties."));
        Map<String, Object> properties = entityManagerFactoryBean.getJpaPropertyMap();
        properties.put("hibernate.ejb.naming_strategy", jpaPropertyResolver.getProperty("hibernate.naming-strategy", SpringNamingStrategy.class.getName()));
        properties.put("hibernate.hbm2ddl.auto", jpaPropertyResolver.getProperty("hibernate.ddl-auto", "none"));
        properties.put("hibernate.show_sql", jpaPropertyResolver.getProperty("hibernate.show_sql", "false"));
        return entityManagerFactoryBean;
    }
}

我的主要:

    @SpringBootApplication
    @EnableJpaRepositories(basePackages = {"com.myproject.vas.aftersales.repository"})
    @ComponentScan(basePackages = {"com.myproject"})
    public class VasApplication {
        public static void main(String[] args) {
            SpringApplication.run(VasApplication.class, args);
        }
    }

我的 POM:

<?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>

    <artifactId>my-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    ...

    <dependencies>
        <!-- Vaadin -->
        ... Vaadin dependencies

        <!-- hibernate dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
        </dependency>

        <!-- testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.1.6.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <!--<version>4.0.3.RELEASE</version>-->
        </dependency>
    </dependencies>
</project>

更新

mvn 依赖:树

[INFO] --- maven-dependency-plugin:2.9:tree (default-cli) @ infopoint ---
[INFO] com.asadventure:infopoint:jar:0.0.1-SNAPSHOT
[INFO] +- com.asadventure:customer-service:jar:crm-SNAPSHOT:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-consul-all:jar:1.0.0.M4:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-starter-consul-config:jar:1.0.0.M4:compile
[INFO] |  |  |  \- org.springframework.cloud:spring-cloud-starter-consul:jar:1.0.0.M4:compile
[INFO] |  |  \- org.springframework.cloud:spring-cloud-starter-consul-discovery:jar:1.0.0.M4:compile
[INFO] |  |     \- org.springframework.cloud:spring-cloud-netflix-core:jar:1.0.3.RELEASE:compile
[INFO] |  +- com.asadventure:LoggingUtils:jar:1.0.0:compile
[INFO] |  |  +- org.springframework:spring-webmvc:jar:4.2.3.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.0.22:compile
[INFO] |  |  \- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.6.3:compile
[INFO] |  +- com.asadventure:job-fetch-interface:jar:crm-SNAPSHOT:compile
[INFO] |  +- com.asadventure:data-utils:jar:crm-SNAPSHOT:compile
[INFO] |  |  +- com.datastax.cassandra:cassandra-driver-core:jar:2.1.6:compile
[INFO] |  |  |  \- com.codahale.metrics:metrics-core:jar:3.0.2:compile
[INFO] |  |  \- org.springframework.data:spring-data-cassandra:jar:1.1.2.RELEASE:compile
[INFO] |  |     \- org.springframework.data:spring-cql:jar:1.1.2.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-web:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.3.0.RELEASE:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.0.28:compile
[INFO] |  |  |  +- org.apache.tomcat.embed:tomcat-embed-logging-juli:jar:8.0.28:compile
[INFO] |  |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.0.22:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-validation:jar:1.3.0.RELEASE:compile
[INFO] |  |  |  \- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  |  |     +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  |     \- com.fasterxml:classmate:jar:1.1.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-starter-zuul:jar:1.0.2.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-starter:jar:1.0.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-actuator:jar:1.3.0.RELEASE:compile
[INFO] |  |  |  \- org.springframework.boot:spring-boot-actuator:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework.cloud:spring-cloud-starter-hystrix:jar:1.0.2.RELEASE:compile
[INFO] |  |  |  +- com.netflix.hystrix:hystrix-metrics-event-stream:jar:1.4.4:compile
[INFO] |  |  |  \- com.netflix.hystrix:hystrix-javanica:jar:1.4.4:compile
[INFO] |  |  |     +- org.aspectj:aspectjrt:jar:1.8.7:runtime
[INFO] |  |  |     \- com.google.code.findbugs:jsr305:jar:3.0.0:runtime
[INFO] |  |  +- org.springframework.cloud:spring-cloud-starter-ribbon:jar:1.0.2.RELEASE:compile
[INFO] |  |  |  \- com.netflix.rxjava:rxjava-core:jar:0.20.7:compile
[INFO] |  |  \- com.netflix.zuul:zuul-core:jar:1.0.28:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-security:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-config:jar:4.0.3.RELEASE:compile
[INFO] |  +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.8.RELEASE:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.9:compile
[INFO] |  +- org.springframework.security:spring-security-jwt:jar:1.0.3.RELEASE:compile
[INFO] |  +- joda-time:joda-time:jar:2.8.1:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.hateoas:spring-hateoas:jar:0.19.0.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.13:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.3:compile
[INFO] |  +- org.projectlombok:lombok:jar:1.16.2:compile
[INFO] |  +- net.sf.dozer:dozer:jar:5.5.1:compile
[INFO] |  +- com.datastax.cassandra:cassandra-driver-dse:jar:2.1.6:compile
[INFO] |  +- com.datastax.cassandra:cassandra-driver-mapping:jar:2.1.4:compile
[INFO] |  +- com.stratio.cassandra:cassandra-lucene-index-builder:jar:2.2.4.0:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.1:compile
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.4.1:compile
[INFO] |  +- com.google.guava:guava:jar:18.0:compile
[INFO] |  +- com.netflix.archaius:archaius-core:jar:0.6.5:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] |  |  \- com.google.code.findbugs:annotations:jar:2.0.0:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.8:compile
[INFO] |  |  \- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- com.ecwid.consul:consul-api:jar:1.1.6:compile
[INFO] |  |  \- com.google.code.gson:gson:jar:2.3.1:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-context:jar:1.0.2.RELEASE:compile
[INFO] |  |  \- org.springframework.security:spring-security-crypto:jar:3.2.7.RELEASE:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-commons:jar:1.0.2.RELEASE:compile
[INFO] |  +- com.netflix.ribbon:ribbon:jar:2.1.0:compile
[INFO] |  |  +- com.netflix.ribbon:ribbon-core:jar:2.1.0:compile
[INFO] |  |  +- com.netflix.ribbon:ribbon-transport:jar:2.1.0:runtime
[INFO] |  |  |  +- io.reactivex:rxnetty-contexts:jar:0.4.9:runtime
[INFO] |  |  |  \- io.reactivex:rxnetty-servo:jar:0.4.9:runtime
[INFO] |  |  +- com.netflix.hystrix:hystrix-core:jar:1.4.4:compile
[INFO] |  |  +- javax.inject:javax.inject:jar:1:runtime
[INFO] |  |  \- io.reactivex:rxnetty:jar:0.4.9:runtime
[INFO] |  |     +- io.netty:netty-codec-http:jar:4.0.27.Final:runtime
[INFO] |  |     |  +- io.netty:netty-codec:jar:4.0.27.Final:runtime
[INFO] |  |     |  \- io.netty:netty-handler:jar:4.0.27.Final:runtime
[INFO] |  |     \- io.netty:netty-transport-native-epoll:jar:4.0.27.Final:runtime
[INFO] |  +- com.netflix.ribbon:ribbon-httpclient:jar:2.1.0:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  +- com.sun.jersey:jersey-client:jar:1.13:runtime
[INFO] |  |  |  \- com.sun.jersey:jersey-core:jar:1.13:runtime
[INFO] |  |  +- com.sun.jersey.contribs:jersey-apache-client4:jar:1.11:runtime
[INFO] |  |  \- com.netflix.netflix-commons:netflix-commons-util:jar:0.1.1:compile
[INFO] |  \- com.netflix.ribbon:ribbon-loadbalancer:jar:2.1.0:compile
[INFO] |     \- com.netflix.netflix-commons:netflix-statistics:jar:0.1.1:runtime
[INFO] +- com.asadventure:customer-service-client:jar:docker-SNAPSHOT:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-context-support:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-web:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |  |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-hateoas:jar:1.3.0.RELEASE:compile
[INFO] |  |  \- org.springframework.plugin:spring-plugin-core:jar:1.2.0.RELEASE:compile
[INFO] |  +- xml-apis:xml-apis:jar:1.3.02:compile
[INFO] |  +- io.netty:netty-buffer:jar:4.0.27.Final:compile
[INFO] |  +- io.netty:netty-transport:jar:4.0.27.Final:compile
[INFO] |  +- io.reactivex:rxjava:jar:1.0.4:compile
[INFO] |  +- io.netty:netty-common:jar:4.0.27.Final:compile
[INFO] |  +- com.netflix.servo:servo-core:jar:0.7.5:compile
[INFO] |  +- org.springframework.cloud:spring-cloud-consul-config:jar:1.0.0.M4:compile
[INFO] |  \- org.springframework.cloud:spring-cloud-consul-discovery:jar:1.0.0.M4:compile
[INFO] |     \- org.springframework.cloud:spring-cloud-consul-core:jar:1.0.0.M4:compile
[INFO] +- com.asadventure:wso2-filter:jar:abeq-SNAPSHOT:compile
[INFO] |  \- org.springframework.ws:spring-ws-core:jar:2.2.3.RELEASE:compile
[INFO] |     +- org.springframework.ws:spring-xml:jar:2.2.3.RELEASE:compile
[INFO] |     \- org.springframework:spring-oxm:jar:4.1.6.RELEASE:compile
[INFO] +- com.vaadin:vaadin-server:jar:7.6.0:compile
[INFO] |  +- com.vaadin:vaadin-sass-compiler:jar:0.9.13:compile
[INFO] |  |  +- org.w3c.css:sac:jar:1.3:compile
[INFO] |  |  +- com.vaadin.external.flute:flute:jar:1.3.0.gg2:compile
[INFO] |  |  \- com.yahoo.platform.yui:yuicompressor:jar:2.4.8:compile
[INFO] |  |     \- rhino:js:jar:1.7R2:compile
[INFO] |  +- com.vaadin:vaadin-shared:jar:7.6.0:compile
[INFO] |  |  +- com.vaadin.external.streamhtmlparser:streamhtmlparser-jsilver:jar:0.0.10.vaadin1:compile
[INFO] |  |  \- com.vaadin.external.google:guava:jar:16.0.1.vaadin1:compile
[INFO] |  \- org.jsoup:jsoup:jar:1.8.3:compile
[INFO] +- com.vaadin:vaadin-client-compiled:jar:7.6.0:compile
[INFO] +- com.vaadin:vaadin-spring-boot-starter:jar:1.0.0:compile
[INFO] |  +- com.vaadin:vaadin-spring-boot:jar:1.0.0:compile
[INFO] |  |  \- com.vaadin:vaadin-spring:jar:1.0.0:compile
[INFO] |  \- com.vaadin:vaadin-themes:jar:7.6.0:compile
[INFO] +- org.vaadin:viritin:jar:1.39:compile
[INFO] |  +- org.vaadin.addon:confirmdialog:jar:2.1.3:compile
[INFO] |  +- org.commonjava.googlecode.markdown4j:markdown4j:jar:2.2-cj-1.0:compile
[INFO] |  +- commons-io:commons-io:jar:1.3.2:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO] |  \- javax.el:javax.el-api:jar:2.2.4:compile
[INFO] +- com.vaadin:grid-renderers-collection-addon:jar:0.92:compile
[INFO] +- de.datenhahn.vaadin:componentrenderer:jar:0.1.1:compile
[INFO] |  \- cglib:cglib:jar:3.2.0:compile
[INFO] |     +- org.ow2.asm:asm:jar:5.0.3:compile
[INFO] |     \- org.apache.ant:ant:jar:1.9.4:compile
[INFO] |        \- org.apache.ant:ant-launcher:jar:1.9.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.3.0.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.7:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.3.0.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.0.28:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.0.28:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.2.3.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:4.3.6.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
[INFO] |  |  +- org.hibernate:hibernate-core:jar:4.3.6.Final:compile
[INFO] |  |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.9.1.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.11.1.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.2.3.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-tx:jar:4.2.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.1.6.RELEASE:compile
[INFO] +- com.microsoft.sqlserver:sqljdbc4:jar:3.0:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.springframework:spring-test:jar:4.1.6.RELEASE:test
[INFO] |  \- org.springframework:spring-core:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:4.0.3.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework.security:spring-security-core:jar:4.0.3.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.3.0.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.0.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.16:compile
[INFO] \- org.springframework.boot:spring-boot-starter-log4j2:jar:1.2.3.RELEASE:compile
[INFO]    +- org.slf4j:jcl-over-slf4j:jar:1.7.13:compile
[INFO]    +- org.slf4j:jul-to-slf4j:jar:1.7.13:compile
[INFO]    +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.4.1:compile
[INFO]    +- org.apache.logging.log4j:log4j-api:jar:2.4.1:compile
[INFO]    \- org.apache.logging.log4j:log4j-core:jar:2.4.1:compile

我们已经运行了一个 Cassandra 数据库,这将添加一个 mssql 数据库。一位同事指出它试图使用 Cassandra 而不是 mssql:

Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185) ~[spring-data-commons-1.11.1.RELEASE.jar:?]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) ~[spring-data-commons-1.11.1.RELEASE.jar:?]
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) ~[spring-data-commons-1.11.1.RELEASE.jar:?]
    at org.springframework.data.cassandra.repository.support.CassandraRepositoryFactoryBean.afterPropertiesSet(CassandraRepositoryFactoryBean.java:62) ~[spring-data-cassandra-1.1.2.RELEASE.jar:?]

【问题讨论】:

  • 你能发布整个 POM 吗?您是否使用版本号定义了任何属性? mvn dependency:tree 的输出也会有所帮助。
  • 我们从父 pom 扩展,所以当前没有任何版本。我添加了依赖树!
  • 对于初学者,请停止混合 spring 版本...您有 4.1.6 和 4.2.3 类不起作用(您也在混合启动 1.2.3 和 1.3.0)。确保您使用适当的版本进行 Spring 引导。 (还想知道为什么要手动配置 entitymanagerfactory 而不是使用自动配置的?您配置的任何内容都不是自动配置的?

标签: hibernate maven jpa spring-boot vaadin


【解决方案1】:

AbstractMethodError 几乎在所有情况下都是不匹配依赖项的结果。当两个版本不兼容的库最终出现在类路径 AbstractMethodError 上时。

在您的情况下,问题可能是由您指定的几个与持久性相关的依赖项引起的。默认情况下,您不应该在使用时指定 JPA/Hibernate 依赖项:

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

例如,如果您检查this tutorial,您将看到正在运行的应用程序的final pom 仅包含一个驱动程序jar (h2),而不是用于持久性的引导启动器依赖项。

【讨论】:

  • 我尝试删除所有 JPA/Hibernate 依赖项,但遗憾的是我仍然遇到同样的错误。我什至尝试像您建议的那样添加另一个驱动程序 jar。不过感谢您的回复!
  • 不要添加任何新内容。只需删除这 3 个并留下这两个:spring-boot-starter-data-jpa 和 sqljdbc4。
  • 仍然没有,但这可能是正确的一步。
  • 你能从你的 WEB-INF/lib 中发布一个完整的 jar 列表吗?
  • 一个spring boot项目有没有WEB-INF/lib?
【解决方案2】:

尝试从 AfterSalesFileRepository 中删除 @Component。如果您启用了@ComponentScan,那么spring boot 将自动为扩展JpaRepository 的任何接口创建存储库实现

【讨论】:

    【解决方案3】:

    当您查看依赖关系树时,您会看到您正在混合使用 Spring Boot 1.2.3 和 1.3.0 中的 Spring Boot jar 版本。切勿混合版本。因此,您还会混合使用 Spring 4.1.6 和 4.2.3 的版本,这总是很危险的。

    对于初学者,请删除 spring-data-jpahibernatespring-security 依赖项并使用 Spring Security 的启动程序 (spring-boot-starter-security) 而不是手动添加依赖项。 (起动器带来了适当的版本)。

    同时删除 spring-testjunit 依赖项,并使用 spring-boot-starter-test&lt;scope&gt;test&lt;/scope&gt; 作为依赖项。

    接下来是为 spring boot 1.2.3 引入 spring-boot-starter-log4j 修复此问题,以便为您的启动版本使用正确的版本。

    您还想再次使用 cassandra,为此请使用启动器 spring-boot-starter-data-cassandra

    还有一个旧的spring-security-crypto jar 被拉入(3.2.7 而不是 4.0.3),这也将导致其他 jar 的依赖关系较旧。

    使用启动器可以避免您指定版本(或者可以防止您添加错误的版本)。

    <dependencies>
        <!-- Vaadin -->
        ... Vaadin dependencies
    
        <!-- hibernate dependencies -->
        <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-cassandra</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
    
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
        </dependency>
    
        <!-- testing -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>        
    </dependencies>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-04
      • 2016-03-08
      • 2016-10-12
      • 2017-11-20
      • 2020-03-16
      • 2018-12-16
      • 2021-12-13
      • 2018-03-17
      相关资源
      最近更新 更多