I have been trying to integrate Struts 2 with Zero Configuration, Spring, Hibernate and Maven.
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
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>
It throws me this exception
Caused by: Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
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>
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.
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.
Also see the example of developing a maven project.
来源:https://stackoverflow.com/questions/17821441/conflicts-in-xwork-and-xwork-core