Struts2 部署时出错:无法加载 bean:类型:类:com.opensymphony.xwork2.ObjectFactory [英] Struts2 Error when Deploying: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory

查看:33
本文介绍了Struts2 部署时出错:无法加载 bean:类型:类:com.opensymphony.xwork2.ObjectFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个基本的 Struts2、Maven webApp,并在部署到 Tomcat 6 或 Jetty 时出现此错误.有人见过吗?

I'm creating a basic Struts2, Maven webApp and getting this error when I deploy to Tomcat 6 or Jetty. Has anyone seen this?

  2010-07-29 15:33:38.801::WARN:  failed struts2
    Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/C:/workspaces/test/test/target/work/webapp/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72
     at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:208)
     at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
     at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:131)
     at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
     at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:395)
     at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:452)
     at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
     at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
     at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:589)
     at org.mortbay.jetty.servlet.Context.startContext(Context.java:139)
     at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
     at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:510)
     at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
     at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:110)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
     at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
     at org.mortbay.jetty.Server.doStart(Server.java:222)
     at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
     at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
     at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:357)
     at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:293)
     at org.mortbay.jetty.plugin.Jetty6RunWar.execute(Jetty6RunWar.java:67)
     at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
     at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
     at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
     at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
     at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
     at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:592)
     at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
     at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
     at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
     at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
    Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/C:/workspaces/ulearn/ulearn/target/work/webapp/WEB-INF/lib/struts2-core-2.0.11.2.jar!/struts-default.xml:30:72 - bean - jar:file:/C:/workspaces/ulearn/ulearn/target/work/webapp/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72
     at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:193)
 ... 47 more

使用 Maven...

Using Maven...

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

web.xml

 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

看起来很简单,我不明白为什么它不会加载.我遵循了基本教程.我用谷歌搜索了这条错误消息,但找不到任何相关信息.

Look's pretty straight forward, I don't understand why it won't load. I followed the basic tutorial. I googled for this error message, and was unable to find anything relevant.

推荐答案

如果你阅读堆栈跟踪,你的问题其实很清楚:

Your problem is actually quite clear if you read the stack trace:

Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the 
name xwork has already been loaded by bean -
jar:file:/C:/workspaces/ulearn/ulearn/target/work/webapp/WEB-INF/lib/struts2-core-2.0.11.2.jar!/struts-default.xml:30:72
 - bean -
jar:file:/C:/workspaces/ulearn/ulearn/target/work/webapp/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72

您有一份 struts2-core-2.0.11.2.jar 一份 struts2-core-2.1.8.1.jar 在您的 WEB-INF/lib 目录中.我认为你应该只拥有其中一个.做一些清理工作(运行 mvn clean 可能就足够了).

You have a copy of struts2-core-2.0.11.2.jar and a copy of struts2-core-2.1.8.1.jar in your WEB-INF/lib directories. I think you should only have one of them. Do some cleanup (running a mvn clean might be enough).

PS:我不知道为什么你也有来自 C:/workspace/test 的东西,如第一行所示:

PS: I have no idea why you also have stuff coming from C:/workspace/test as show be the first line:

jar:file:/C:/workspaces/test/test/target/work/webapp/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72

你的类路径肯定有一些奇怪和混乱的东西.除了我上面给出的解释之外,我没有任何解释.

There is definitely something weird and messy with your classpath. I don't have any explanation beyond the one I gave above though.

这篇关于Struts2 部署时出错:无法加载 bean:类型:类:com.opensymphony.xwork2.ObjectFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆