【问题标题】:Maven Dependency - NoSuchMethodError on org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/PropertiesMaven 依赖 - org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties 上的 NoSuchMethodError
【发布时间】:2017-10-04 00:05:26
【问题描述】:

我正在关注this blogpost 设置休眠持久层。

我当前的 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>projectname</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>selfserve.Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>1.5.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>1.5.7.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.11.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.5.6-Final</version>
    </dependency>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.9.9</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>23.1-jre</version>
    </dependency>
</dependencies>

我收到以下错误:

Caused by: java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getProperties()Ljava/util/Properties;
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:124)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:890)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
... 21 more

看起来我的一些依赖项相互冲突,但我真的不确定是哪一个。网上没有任何迹象表明有任何冲突。

任何帮助或指导将不胜感激!

【问题讨论】:

    标签: spring hibernate maven jpa intellij-idea


    【解决方案1】:

    您的类 - org.hibernate.engine.spi.SessionFactoryImplementor - 从依赖中解决。

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.11.Final</version>
    </dependency>
    

    而且这个类不包含 getProperties() 方法。请看一下源代码。

    摆脱这种依赖。然后您的类将从依赖项中解析 - hibernate-core: 5.0.12.Final 和 org.hibernate.engine.spi.SessionFactoryImplementor 此 jar 中的类包含 getProperties() 方法。

    如果您遇到任何问题,请告诉我们。

    【讨论】:

    • 太棒了!那解决了它。现在我会知道检查依赖关系树。非常感谢!
    • 感谢您告诉我们!
    【解决方案2】:

    我在使用 EhCache 时遇到了同样的问题。显然 EhCache 依赖依赖于不同版本的hibernate-core,导致冲突。改回对应的版本解决了这个问题:

    // https://mvnrepository.com/artifact/org.hibernate/hibernate-ehcache
    compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.0.12.Final'
    

    鉴于hibernate-core 版本5.0.12 当然是spring-boot-starter-data-jpa 所依赖的版本(确实如此!)。

    【讨论】:

      【解决方案3】:

      仅使用hibernate 5.2 使用hibernate-core:5.2.x.Final 并排除hibernate-entitymanager,因为它已被弃用。

      【讨论】:

        猜你喜欢
        • 2018-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多