2012-09-04 38 views
1

我想添加休眠到我的春天項目的數據庫持久性,我已經下載了休眠4.1.6最新的穩定版本,我使用的是Spring 3.1。當試圖添加休眠到春天項目時出錯

然而,當我嘗試運行項目中,我得到:

我已經添加到我的項目外罐到目前爲止是:

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> 

感謝您的幫助,對我的問題所做的任何更改請讓m我知道。

丹尼爾

+0

http://stackoverflow.com/questions/12261899/failed-to-load-applicationcontext-with-contextconfigurationclasses http://stackoverflow.com/questions/11863235/junit-testcase-passes-with-eclipse-but-fails- with-maven-build看起來像是重複的,它與jee依賴關係 –

+0

另一個奇怪的東西,你說rence hibernate實體管理器(它引用了hibernate)並使用單獨的jar文件。你也有你的配置中的jee依賴和jpa 2實現jar文件我猜想它可能是不同衝突的來源 –

回答

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

更新它不明白爲什麼你已經下載單獨的休眠jar文件(包括JPA 2.0實現),如果你有Hibernate的實體管理器和Java EE的依賴在你的pom.xml

+0

哦,它可能只是遵循各種設置教程,我會減少它以刪除重複以後,謝謝你,雖然你的解決方案工作! – user1646196