1

我正在尝试将hibernate添加到我的spring项目中以实现数据库持久性,我已经下载了最新的稳定版本hibernate 4.1.6,并且正在使用spring 3.1。

但是,当我尝试运行我的项目时,我得到:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 
'org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0': 
Invocation of init method failed; nested exception is java.lang.ClassFormatError:   
Absent Code attribute in method that is not native or abstract in class file  
javax/validation/Validation

到目前为止,我添加到项目中的外部 jar 是:

antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.1.Final.jar
hibernate-core-4.1.6.Final.jar
hibernte-jpa-2.0-api-1.0.1.Final.jar
javassist-3.15.0-GA.jar
jboss-logging-3.1.0.GA.jar
jboss-transaction-api_1.1_spec-1.0.0.Final.jar
hibernate-entitymanager-4.1.6.Final.jar
slf4j-api-1.6.1.jar

我的 pom.xml 包含以下依赖项:

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

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.1.2</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>2.2.2</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.0</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <scope>runtime</scope>
    <version>1.1.2</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
</dependency>

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
</dependency>


<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.10</version>
    <scope>test</scope>
</dependency>
</dependencies>

感谢您的帮助,对我的问题应该进行的任何更改,请告诉我。

丹尼尔

4

1 回答 1

1

Maven 存储库中的依赖项似乎存在问题javaee-api,作为一种解决方案,您可以切换到替代方案

   <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-ejb_3.1_spec</artifactId>
       <version>1.0</version>
       <scope>provided</scope>
   </dependency>
   <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-jpa_2.0_spec</artifactId>
       <version>1.0</version>
       <scope>provided</scope>
   </dependency>

致谢:这里讨论了这个解决方案。

另请参阅Failed to load ApplicationContext with @ContextConfiguration(classes={ ... })JUnit 测试用例通过 eclipse 但因 maven build 失败

更新如果您的 pom.xml 中有 Hibernate 实体管理器和 Java EE 依赖项,则不明白为什么您下载了单独的 hibernate jar 文件(包括 JPA 2.0 实现)

于 2012-09-04T16:31:10.390 回答