Exception starting filter struts2(Caught exception while loading file struts-default.xml )

2008-9-18 11:31:57 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Caught exception while loading file struts-default.xml - [unknown location]
 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:795)
 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:132)
 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:100)
 at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload(DefaultConfiguration.java:130)
 at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:52)
 at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:398)
 at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:455)
 at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:201)
 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:3709)
 at org.apache.catalina.core.StandardContext.start(StandardContext.java:4356)
 at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3099)
 at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:404)
 at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1309)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
 at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
 at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.XML11Configuration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
 at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
 at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
 at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
 at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder(Unknown Source)
 at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.<init>(Unknown Source)
 at com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputHandlerFactory.getSerializationHandler(Unknown Source)
 at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source)
 at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerHandlerImpl.setResult(Unknown Source)
 at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.setup(DomHelper.java:213)
 at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init>(DomHelper.java:198)
 at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init>(DomHelper.java:189)
 at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init>(DomHelper.java:175)
 at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:115)
 at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:786)
 ... 20 more
2008-9-18 11:31:57 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2008-9-18 11:31:57 org.apache.catalina.core.StandardContext start
严重: Context [/DataManager] startup failed due to previous errors
2008-9-18 11:31:57 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
在开发过程中总遇到这个问题,看到同事博客里介绍的解决方法:

                 移除项目目录中的xerces.jar

针对上面这个异常导致的原因解析如下:

Why do I get a ClassCastException when I use Xerces and WebSphere Application Server?
 

Xerces uses the ObjectFactory class to load some classes dynamically, e.g. the parser configuration. The ObjectFactory finds the specified implementation class by querying the system property, reading META-INF/services/factoryId file or using a fallback classname. After the implementation is found, the ObjectFactory tries to load the file using the context classloader and if it is null, the ObjectFactory uses the system classloader.

If you run Xerces in an environment, such as WebSphere® Application Server, that has multiple classloaders you may get ClassCastExceptions thrown from Xerces because different classloaders might get involved in loading Xerces classes. For example, ClassCastExceptions may occur when utility EAR classes that use Xerces load Xerces classes from WAR modules.

We suggest you read the "Avoiding ClassCastExceptions..." article which explains a workaround for this problem. Also you might want to read the "J2EE Class Loading Demystified" article that explains how multiple classloaders work in WebSphere Application Server.

可以参考:

http://markmail.org/message/zzn5zl4wv5crrtan#query:java.lang.ClassCastException%3A%20org.apache.xerces.parsers.XML11Configuration%20cannot%20be%20cast%20to%20org.apache.xerces.xni.parser.XMLParserConfiguration+page:1+mid:zzn5zl4wv5crrtan+state:results

http://xerces.apache.org/xerces2-j/faq-general.html#faq-5

但网上也有朋友说该方法试了没用,这主要是我们的开发环境中导入的Struts中的lib下的包不一样,也许对于初学者,可能想导入所有的包应该没问题,而这恰恰是导致该问题的所在。有很多朋友说当自己导入所有的包时出现

Exception starting filter struts2
Caught exception while loading file struts-default.xml

但如果只导入struts2下的实例blank中的5个包则没有问题。因为struts2中lib下有很多插件plugin等包。如:有朋友说在项目中根本没有采用spring架构,但配置了spring后才不出现该问题,其实这是因为他导入了struts2-spring-plugin-2.0.11.jar。所以根据控制台报出的具体错误找出问题之所在。看看你的项目中具体是哪个出了问题。

你可能感兴趣的:(exception,struts,filter,File,application,websphere)