Unable to load configuration. - bean struts-default.xml struts2中的jar包冲突
花了整整一天的时间来解决这个问题, 记录来来供大家分享一下。
在我的网站http://txw100.com/forumAction.action?topicID=45&classid=1里作了祥的记录, 希望能给后面的兄弟带来帮助。
一、问题:
严重: Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/D:/Struts2/workp/.metadata/.me_tcat/webapps/gclStruts2/WEB-INF/lib/struts2-core-2.1.8.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)
解决方法: http://txw100.com/forumAction.action?topicID=45&classid=1
1. 从struts官网下载最新的jar包
网址:http://struts.apache.org/download.cgi#struts232-SNAPSHOT
struts2必须的包有:
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
json-lib-2.3-jdk15.jar
ognl-3.0.5.jar
struts2-core-2.3.4.jar
xwork-core-2.3.4.jar
我是加入了上面的10个包才OK的。
二、问题:
java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils .
解决方法:
在WEB-INF/lib中加入commons-lang3-3.1.jar
=================================================
严重: Exception starting filter struts2
Unable to load configuration. - bean - jar:file:/F:/workspace/swbaidu/WebContent/WEB-INF/lib/struts2-core-2.3.4.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:360)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
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:3800)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4450)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
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:583)
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:/workspace/swbaidu/WebContent/WEB-INF/lib/struts2-core-2.3.4.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:222)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:101)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:165)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)
... 21 more
Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with the name xwork has already been loaded by bean - jar:file:/F:/workspace/aa/WebContent/WEB-INF/lib/struts2-core-2.1.6.jar!/struts-default.xml:29:72 - bean - jar:file:/F:/workspace/swbaidu/WebContent/WEB-INF/lib/struts2-core-2.3.4.jar!/struts-default.xml:29:72
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:206)
... 24 more
解决方法:
从黄色部分可看出struts2-core的jar包冲突了。
看看tomcat中的conf/server.xml文件的配置:
<Context path="/aa" docBase="F:\workspace\wj\WebContent" reloadable="false"/>
<Context path="/swbaidu" docBase="F:\workspace\swbaidu\WebContent" reloadable="false"/>
这里配两个是没问题的,
那么再看看eclipse中的tomcat的配置:
windows-->preferences-->Tomcat-->Advanced--> Add Java projects to Tomcat classpath
由于上面已在conf/server.xml中作了配置这里就不用再打沟了,否则会报错。