2013-07-23 47 views
1

我一直在嘗試將Struts 2與零配置,Spring,Hibernate和Maven集成。xwork和xwork-core的衝突

但是,我認爲必須有一些東西,我在集成的思念,它必須與Maven的Pom.xml的配置:

<dependency> 
    <groupId>org.apache.struts</groupId> 
    <artifactId>struts2-core</artifactId> 
    <version>2.1.8.1</version> 
</dependency> 

<!-- Struts 2 + Spring plugins --> 
<dependency> 
    <groupId>org.apache.struts</groupId> 
    <artifactId>struts2-spring-plugin</artifactId> 
    <version>2.1.8.1</version> 
</dependency> 

<!-- MySQL database driver --> 
<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.9</version> 
</dependency> 

<!-- Spring framework --> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring</artifactId> 
    <version>2.5.6</version> 
</dependency> 
<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-web</artifactId> 
    <version>2.5.6</version> 
</dependency> 

<!-- Hibernate core --> 
<dependency> 
    <groupId>asm</groupId> 
    <artifactId>asm-all</artifactId> 
    <version>3.3</version> 
</dependency> 
<dependency> 
    <groupId>asm</groupId> 
    <artifactId>asm</artifactId> 
    <version>3.3</version> 
</dependency> 
    <dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-core</artifactId> 
    <version>3.6.7.Final</version> 
</dependency> 

<!-- Hibernate core library dependency start --> 

<!-- Hibernate core library dependency end --> 

<!-- Hibernate query library dependency start --> 
<dependency> 
    <groupId>org.apache.struts</groupId> 
    <artifactId>struts2-convention-plugin</artifactId> 
    <version>2.1.8.1</version> 
</dependency> 
<dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>javax.servlet-api</artifactId> 
    <version>3.0.1</version> 
    <scope>provided</scope> 
</dependency> 
<dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.15</version> 
</dependency> 

,當我使用此配置它給了我一個錯誤

java.lang.NoSuchMethodError: com.opensymphony.xwork2.util.finder.UrlSet.<init>(Lcom/opensymphony/xwork2/util/finder/ClassLoaderInterface;Ljava/util/Set;)V 

而不是OpenSymphony的XWork的我libaray使用

<dependency> 
    <groupId>org.apache.struts.xwork</groupId> 
    <artifactId>xwork-core</artifactId> 
    <version>2.3.8</version> 
</dependency> 
依賴

它將引發我此異常

Caused by: Unable to load configuration. - [unknown location] 
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) 
+1

查看[遷移指南](http://struts.apache.org/release/2.3.x/docs/migration-guide.html) –

+0

在那裏看到什麼? – user2607985

+1

你不能使用任意版本的xwork;請顯示mvn依賴項的輸出:沒有xwork的不正確版本。 –

回答

0

當您升級Struts2的版本,你必須更新庫需要您的應用程序到目標版本。 Struts2的每個發行版都提供了lib文件夾中與發行版本兼容的相應庫集。如果您使用maven來解析並獲取依賴關係,則應該考慮工件struts2-core

<dependency> 
    <groupId>org.apache.struts</groupId> 
    <artifactId>struts2-core</artifactId> 
    <version>2.3.8</version> 
</dependency> 

將取回了這件神器所有需要的依賴,其他的依賴,比如插件,你需要單獨添加。使用針對插件的相同版本。例如添加一個約定插件使用

<dependency> 
    <groupId>org.apache.struts</groupId> 
    <artifactId>struts2-convention-plugin</artifactId> 
    <version>2.3.8</version> 
</dependency> 

我選擇2.3.8目標版本號,但它可能不兼容與其他的特徵,即Hibernate和Spring哪些版本需要通過添加相應的單獨升級工件到依賴關係。

最後也是最耗時的是對項目源代碼的更改,根據更新的DTD,API更改和修訂棄用更新配置文件。爲此,請考慮閱讀release notes


另請參閱example of developing a maven project

+0

你可以upvote這個答案。 –