开发者

Struts2 Error when Deploying: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory

开发者 https://www.devze.com 2023-01-09 23:58 出处:网络
I\'m creating a basic Struts2, Maven webApp and getting this error when I deploy to Tomcat 6 or Jetty.Has anyone seen this?

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.j开发者_开发技巧ava: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

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

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: 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.


Agree with the above answer

Check your library and classpath for the above jars and fix them

Sometimes even if the jars are not seen in the IDE, they are present int the build files, So a fix of the classpath and a CLEAN AND BUILD should resolve the problem.


I think struts2-core-2.1.8.1.jar copy or you have included this jar file some where in your webapplication so remove it and continue


Problem: The conflict occurred as 2 files of different versions are being loaded by the web container

Solution: Just go to path C:/workspaces/ulearn/ulearn/target/work/webapp/WEB-INF/lib/ of your computer and delete the struts2-core-2.0.11.2.jar file and only keep the latest one. If this type of conflict also occurs with some other file then delete that file also After this no exception will be there.


I have also encountered this problem recently. Clean the cache and rebuild the project is not valid for my error. I tried to delete the conflicting struts-default.xml file, but I didn't find it and the struts-default.xml file is a read-only file so I can't to modify it. My final solution is to remove the extra Web* under Project Structure--Modules--MyFirstProject (project name), leaving only one Web and modifying Web Resource Directories as WebRoot. It works for me! Hope I can help others. ​​​​​​​​​​here

0

精彩评论

暂无评论...
验证码 换一张
取 消