名为xwork的Bean类com.opensymphony.xwork2.ObjectFactory已经被bean加载

时间:2014-01-28 10:22:54

标签: struts2 embedded-jetty

我正在尝试使用嵌入式Jetty实例部署一个简单的webapp。我的嵌入式测试代码是:

public static void main(String[] args) throws Exception{
    Server server = new Server(8181);
    WebAppContext webAppContext = new WebAppContext();
    webAppContext.setContextPath("/");
    webAppContext.setWar(ContUtil.warPath + ContUtil.warName);
    server.setHandler(webAppContext);

    logger.info("starting jetty...");
    server.start();
    server.join();
} 

但我收到以下错误:

Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/C:/Users/lingguo/AppData/Local/Temp/jetty-0.0.0.0-8181-MemCloud-Web-1.0-SNAPSHOT.war-_-any-6830790104248388668.dir/webapp/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:29:72
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:232)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:180)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
    ... 23 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/D:/Program%20Files%20(x86)/apache-maven-2.2.1/repo/org/apache/struts/struts2-core/2.2.1/struts2-core-2.2.1.jar!/struts-default.xml:29:72 - bean - jar:file:/C:/Users/lingguo/AppData/Local/Temp/jetty-0.0.0.0-8181-MemCloud-Web-1.0-SNAPSHOT.war-_-any-6830790104248388668.dir/webapp/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:29:72
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:216)
    ... 26 more

我引用了许多关于这个问题的类似答案,例如:Struts2 Error when Deploying: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory;大多数类似的问题都是由不同版本的jar包冲突引起的。但我的问题有点不同。我确保在我的类路径中只有一个版本的struts2-core(2.2.1)。

我检查了错误消息,我认为jetty创建了一个tmp文件,即:/C:/Users/lingguo/AppData/Local/Temp/jetty-0.0.0.0-8181-MemCloud-Web-1.0-SNAPSHOT.war-_-any-6830790104248388668.dir,并且jar struts2-core-2.2.1与我本地maven存储库中的jar有关。

有谁知道哪里出错了?提前谢谢!

0 个答案:

没有答案