繁体   English   中英

调用init方法失败; 添加Hibernate枚举后,嵌套异常为java.lang.NoSuchMethodError

[英]Invocation of init method failed; nested exception is java.lang.NoSuchMethodError after adding Hibernate envers

我正在尝试将hibernate-envers添加到我们的Spring MVC项目之一。 我的实体类在单独的maven模块中,我在那里使用envers,然后将其安装为本地maven存储库,并在我的实际Spring项目中用作依赖项。 一切正常,没有麻烦。 我在Spring项目中用于休眠的依赖树是:

[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.3.9.Final:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.4.Final:compile
[INFO] +- org.hibernate:hibernate-ehcache:jar:5.3.9.Final:compile
[INFO] |  \- (org.hibernate:hibernate-core:jar:5.3.9.Final:compile - omitted for duplicate)
[INFO] +- org.hibernate:hibernate-spatial:jar:5.3.9.Final:compile
[INFO] |  \- (org.hibernate:hibernate-core:jar:5.3.9.Final:compile - omitted for duplicate)
[INFO] +- az.asdf.dcs:az.asdf.dcs.core:jar:1.1:compile
[INFO] |  +- (org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile - omitted for duplicate)
[INFO] |  +- (org.hibernate:hibernate-core:jar:4.3.6.Final:compile - omitted for conflict with 5.3.9.Final)
[INFO] |  +- (org.hibernate:hibernate-spatial:jar:4.3-SNAPSHOT:compile - omitted for conflict with 5.3.9.Final)
[INFO] |  \- (org.hibernate:hibernate-envers:jar:5.3.9.Final:compile - omitted for duplicate)
[INFO] \- org.hibernate:hibernate-envers:jar:5.3.9.Final:compile
[INFO]    \- (org.hibernate:hibernate-core:jar:5.3.9.Final:compile - omitted for duplicate)

对于Spring依赖项:

[INFO] +- org.springframework:spring-core:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.3.3.RELEASE:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.3.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-beans:jar:4.3.3.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-context:jar:4.3.3.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-aop:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-beans:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-expression:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-expression:jar:4.3.3.RELEASE:compile
[INFO] |  |  \- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  \- org.springframework:spring-web:jar:4.3.3.RELEASE:compile
[INFO] |     +- (org.springframework:spring-aop:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-beans:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |     +- (org.springframework:spring-context:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |     \- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-tx:jar:4.3.3.RELEASE:compile
[INFO] |  +- (org.springframework:spring-beans:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  \- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-orm:jar:4.3.3.RELEASE:compile
[INFO] |  +- (org.springframework:spring-beans:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  +- org.springframework:spring-jdbc:jar:4.3.3.RELEASE:compile
[INFO] |  |  +- (org.springframework:spring-beans:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  |  +- (org.springframework:spring-core:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  |  \- (org.springframework:spring-tx:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] |  \- (org.springframework:spring-tx:jar:4.3.3.RELEASE:compile - omitted for duplicate)
[INFO] +- org.springframework:spring-aspects:jar:4.3.3.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-core:jar:4.2.4.RELEASE:compile
[INFO] |  +- (org.springframework:spring-aop:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-beans:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-context:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-core:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  \- (org.springframework:spring-expression:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] +- org.springframework.security:spring-security-web:jar:4.2.4.RELEASE:compile
[INFO] |  +- (org.springframework.security:spring-security-core:jar:4.2.4.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-beans:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-context:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-core:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-expression:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  \- (org.springframework:spring-web:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] +- org.springframework.security:spring-security-config:jar:4.2.4.RELEASE:compile
[INFO] |  +- (org.springframework.security:spring-security-core:jar:4.2.4.RELEASE:compile - omitted for duplicate)
[INFO] |  +- (org.springframework:spring-aop:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-beans:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  +- (org.springframework:spring-context:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] |  \- (org.springframework:spring-core:jar:4.3.12.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO] \- az.asdf.dcs:az.asdf.dcs.core:jar:1.1:compile
[INFO]    \- org.springframework.data:spring-data-cassandra:jar:2.0.2.RELEASE:compile
[INFO]       +- (org.springframework:spring-context:jar:5.0.2.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO]       +- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO]       +- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO]       +- (org.springframework:spring-tx:jar:5.0.2.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO]       +- (org.springframework:spring-expression:jar:5.0.2.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO]       \- org.springframework.data:spring-data-commons:jar:2.0.2.RELEASE:compile
[INFO]          +- (org.springframework:spring-core:jar:5.0.2.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)
[INFO]          \- (org.springframework:spring-beans:jar:5.0.2.RELEASE:compile - omitted for conflict with 4.3.3.RELEASE)

我在这里看不到任何版本冲突。 但是当我尝试运行时,出现以下异常:

Unsatisfied dependency expressed through field 'sessionFactory'; 
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in class path resource [Spring-Hibernate.xml]:
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.envers.configuration.internal.GlobalConfiguration.<init>(Lorg/hibernate/envers/boot/internal/EnversService;Ljava/util/Map;)V]]

欢迎任何建议。

更新:这是我在核心和Spring项目中的pom.xml:

核心模块:

<dependencies>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.6.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-spatial</artifactId>
        <version>4.3-SNAPSHOT</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-envers -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-envers</artifactId>
        <version>5.3.9.Final</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-cassandra</artifactId>
        <version>2.0.2.RELEASE</version>
    </dependency>

</dependencies>

春季项目:

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <springframework.version>4.3.3.RELEASE</springframework.version>
    <spring.security.version>4.2.4.RELEASE</spring.security.version>
    <hibernate.version>5.3.9.Final</hibernate.version>
</properties>

<dependencies>
    <!--Spring resources-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${springframework.version}</version>
    </dependency>
    <!-- Spring + aspects -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${springframework.version}</version>
    </dependency>

    <!-- Spring Security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>${spring.security.version}</version>
    </dependency> 
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>${spring.security.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>${spring.security.version}</version>
    </dependency>
    <!--Spring resources-->
    <!--Hybernate resources-->
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-ehcache</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-core</artifactId>
        <version>2.6.11</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-spatial</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <!--Hybernate resources-->
    <!-- Apache Commons Upload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.2.2</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>
    <!-- Apache Commons Upload -->
    <!--for Log-->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <!--for Log-->
    <!---->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.4.1211.jre7</version>
    </dependency>
    <!--Jackson JSON Parser-->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.7.5</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.6.3</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.paho</groupId>
        <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
        <version>1.1.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.11</version>
    </dependency>


    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>az.asdf.dcs</groupId>
        <artifactId>az.asdf.dcs.core</artifactId>
        <version>1.1</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-envers</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.asteriskjava/asterisk-java -->
    <dependency>
        <groupId>org.asteriskjava</groupId>
        <artifactId>asterisk-java</artifactId>
        <version>2.0.2</version>
    </dependency>

</dependencies>

spring-corespring-webmvcspring-tx已经在spring-orm
在这里检查: https : //mvnrepository.com/artifact/org.springframework/spring-REPLACE-ME/usages

spring-security-config内的spring-security-config spring-sercurity-web spring-security-core相同内容
您还与使用记录的依赖关系的版本存在冲突

omitted for conflict with 4.3.3.RELEASE

您的依赖项明确指出您正在尝试在代码模块中将Hibernate ORM 4.3.6.Final与Hibernate Envers 5.3.9.Final一起使用。 正如其他人多次提到的,这是一个依赖冲突。

简而言之,Hibernate Envers的版本应该与Hibernate Core的版本相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM