struts.xml文件我写了这个
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" namespace="/">
</package>
</struts>
web.xml文件我写了这个
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
jar文件我参与了web-inf/lib
当我要在eclispe中运行时,这将会出错
>>>SEVERE: Dispatcher initialization failed
>>>Unable to load configuration. - bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
>>> at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
>>> at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)
>>> at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
>>> 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.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
>>> at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
>>> at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
>>> at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3693)
>>> at org.apache.catalina.core.StandardContext.start(StandardContext.java:4340)
>>> at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
>>> at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
>>> at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
>>> at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
>>> at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
>>> at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
>>> at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
>>> at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
>>> at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
>>> at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>>> at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>>> at org.apache.catalina.core.StandardService.start(StandardService.java:516)
>>> at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>>> at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
>>> 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:597)
>>> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>>> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
>>>Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
>>> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:221)
>>> at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
>>> at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:169)
>>> at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
>>> ... 31 more
>>>Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72 - bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
>>> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:205)
>>> ... 34 more
>>>Jan 30, 2014 11:57:43 AM org.apache.catalina.core.StandardContext filterStart
>>>SEVERE: Exception starting filter struts2
>>>Unable to load configuration. - bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
>>> at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:431)
>>> 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.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
>>> at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
>>> at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
>>> at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3693)
>>> at org.apache.catalina.core.StandardContext.start(StandardContext.java:4340)
>>> at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
>>> at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
>>> at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
>>> at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
>>> at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
>>> at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
>>> at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
>>> at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
>>> at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
>>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
>>> at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>>> at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>>> at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>>> at org.apache.catalina.core.StandardService.start(StandardService.java:516)
>>> at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>>> at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
>>> 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:597)
>>> at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>>> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
>>>Caused by: Unable to load configuration. - bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
>>> at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
>>> at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:374)
>>> at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:418)
>>> ... 29 more
>>>Caused by: Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
>>> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:221)
>>> at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
>>> at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:169)
>>> at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
>>> ... 31 more
>>>Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72 - bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
>>> at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:205)
>>> ... 34 more
>>>Jan 30, 2014 11:57:43 AM org.apache.catalina.core.StandardContext start
>>>SEVERE: Error filterStart
>>>Jan 30, 2014 11:57:43 AM org.apache.catalina.core.StandardContext start
>>>SEVERE: Context [/project] startup failed due to previous errors
答案 0 :(得分:8)
堆栈跟踪中提到了您的问题:
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has
already been loaded by bean - jar:file:/F:/m/.metadata/.me_tcat/webapps/project/WEB-INF
/lib/struts2-core-2.1.8.1.jar!/struts-default.xml:29:72 - bean - jar:file:/F:/m/.metadata
/.me_tcat/webapps/project/WEB-INF/lib/struts2-core-2.2.3.jar!/struts-default.xml:29:72
您的struts2-core-*.jar
目录中似乎有WEB-INF/lib
的多个副本。我想你应该只有一个。做一些清理工作。另请查看您的.classpath
是否没有重复的条目。
答案 1 :(得分:5)
这是 jar 问题。你需要下载所有最新的struts罐子。
尝试以下jar库:
所有常见的jar(freemarker.jar,javaassist.jar,ognl.jar,xwork-core.jar,struts2-core.jar)都应该有最新版本。
特别要确保xwork和struts2核心jar具有相同的版本。在Java 8之后,这些jar不再是可选的。
答案 2 :(得分:0)
错误很简单:
类com.opensymphony.xwork2.ObjectFactory,名称为xwork 已经被bean加载了。
您是否已将struts2-core-X.X.X.X.jar添加到服务器类路径?与项目构建路径一起。
如果是,则删除。它会起作用。