xwork 和 xwork-core 中的冲突

Conflicts in xwork and xwork-core(xwork 和 xwork-core 中的冲突)

本文介绍了xwork 和 xwork-core 中的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将 Struts 2 与零配置、Spring、Hibernate 和 Maven 集成.

I have been trying to integrate Struts 2 with Zero Configuration, Spring, Hibernate and Maven.

但是,我认为在集成中肯定有一些我缺少的东西,它必须与Maven的Pom.xml的配置有关:

But, what I think there must be something which I am missing in integration and it must be related to the configuration of Maven's 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>

当我使用这个配置时,它给了我一个错误

As when I use this configuration it gives me an error

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

我使用依赖关系而不是 opensymphony XWork libaray

And instead of opensymphony XWork libaray I use dependency of

<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)

推荐答案

当你升级Struts2的版本时,你必须将你的应用程序需要的库更新到目标版本.Struts2 的每个发行版都在 lib 文件夹中提供了与发行版版本兼容的相应库集.如果您使用 maven 来解析和获取依赖项,您应该考虑工件 struts2-core.

When you upgrade the version of Struts2, you have to update the libraries requires by your application to the target version. Each distro of Struts2 supplied with the corresponding set of libraries in the lib folder that are compatible with the version of distro. If you use maven to resolve and fetch the dependencies you should consider the artifact struts2-core.

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


它将获取此工件所需的所有依赖项,其他依赖项,例如您需要单独添加的插件.使用针对插件的相同版本.例如添加约定插件使用


It will fetch all required dependencies for this artifact, other dependencies, such as plugins you need to add separately. Use the same version targeted to plugins. For example to add a convention plugin use

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


我选择了 2.3.8 的目标版本号,但它可能与其他功能不兼容,即 Hibernate 和 Spring,哪些版本需要通过将相应的工件添加到依赖项来单独升级.


The targeted version number I've chosen 2.3.8 but it's possibly incompatible with the other features i.e. Hibernate and Spring which versions need to upgrade separately by adding corresponding artifacts to the dependencies.

最后也是最耗时的是更改项目的源代码,根据较新的 DTD 更新配置文件,API 更改,修复弃用.为此,请考虑阅读 发行说明.

And finally and most time consuming is changes to the source code of the project, update the configuration files according to newer DTDs , API changes, fix deprecations. For this purpose consider reading the release notes.

另见开发Maven项目的例子:使用 Maven 创建 Struts 2 Web 应用程序来管理工件和构建应用程序.

Also see the example of developing a Maven project: Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application.

这篇关于xwork 和 xwork-core 中的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:xwork 和 xwork-core 中的冲突

基础教程推荐