问题
I am using RAD 7.0 for developing Struts2 app. When I run the web app inside RAD on websphere 6.1, I get following error:
could not be initialized]: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - wsjar:file:/C:/workspace_test/Jars/struts2-core-2.0.11.2.jar!/struts-default.xml:30:72 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:208) .... more Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - wsjar:file:/C:/workspace_test/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/Struts2Demo/WEB-INF/lib/struts2-core-2.0.11.2.jar!/struts-default.xml:30:72 - bean - wsjar:file:/C:/workspace_test/Jars/struts2-core-2.0.11.2.jar!/struts-default.xml:30:72 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:193) ... 33 more
I understand that this is due to 2 copies of struts2 jars. Let me explain how I have configured my web project in the RAD environment.
I have a Web project called "Struts2Demo" project. And a separate project called "JARS" which contains all the required jars.
All the required jars for Struts2Demo web project are configured using "J2EE Module Dependencies - Web Libraries" referencing "JARS" project.
So the RAD while loading the web app is loading the jars from "JARS" project and also from the eclipse temp folder "/C:/workspace_test/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/Struts2Demo/WEB-INF/lib/", hence the error.
So, my question is there any way to fix this configuration other than putting required jars in WEB-INF/lib
回答1:
Zero experience with RAD. But the standard practice, is to put the struts jars (and, in general, most of the jars) in the WEB-INF/lib of each web-application. The duplication inconvenience is usually outweighed by the isolation of classes from each library (different classloaders) among webapps, which helps to avoid problems as yours.
来源:https://stackoverflow.com/questions/2778140/struts2-in-rad-raises-error-xwork-has-already-been-loaded-by-bean