尝试将hibernate添加到spring项目时出错

时间:2012-09-04 15:57:38

标签: spring hibernate maven spring-mvc pom.xml

我正在尝试将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

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

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>

感谢您的帮助,对我的问题所做的任何更改请告诉我。

丹尼尔

1 个答案:

答案 0 :(得分: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>

致谢:此解决方案已经讨论here

另请参阅Failed to load ApplicationContext with @ContextConfiguration(classes={ ... })JUnit testcase passes with eclipse but fails with maven build

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