转载

启动tomcat后struts框架报异常严重: Exception starting filter struts2 Unable to load configur...

今天刚好宿舍断网,打开电脑,打开ide工具,启动tomcat后,访问web项目工程,页面显示404,查看控制台,运行报错信息如下:

严重: Exception starting filter struts2

Unable to load configuration. - Class: java.net.PlainSocketImpl

File: PlainSocketImpl.java

Method: connect

Line: 177 - java/net/PlainSocketImpl.java:177:-1

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.ng.InitOperations.initDispatcher(InitOperations.java:69)

at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:48)

at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)

at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:424)

at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)

at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)

at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)

at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)

at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)

at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)

at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

at org.apache.catalina.core.StandardService.start(StandardService.java:525)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

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:289)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

Caused by: Unable to load file:/D:/apache-tomcat-6.0.37/webapps/spring-ssh/WEB-INF/classes/struts.xml - Class: java.net.PlainSocketImpl

File: PlainSocketImpl.java

Method: connect

Line: 177 - java/net/PlainSocketImpl.java:177:-1

at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:890)

at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadDocuments(XmlConfigurationProvider.java:144)

at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init(XmlConfigurationProvider.java:111)

at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:164)

at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:55)

... 31 more

Caused by: struts.apache.org - Class: java.net.PlainSocketImpl

File: PlainSocketImpl.java

Method: connect

Line: 177 - java/net/PlainSocketImpl.java:177:-1

at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:115)

at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadConfigurationFiles(XmlConfigurationProvider.java:885)

... 35 more

Caused by: java.net.UnknownHostException: struts.apache.org

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

at java.net.Socket.connect(Socket.java:519)

at java.net.Socket.connect(Socket.java:469)

at sun.net.NetworkClient.doConnect(NetworkClient.java:163)

at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)

at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)

at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)

at sun.net.www.http.HttpClient.New(HttpClient.java:306)

at sun.net.www.http.HttpClient.New(HttpClient.java:323)

at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:790)

at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:731)

at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:656)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:979)

at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:677)

at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1315)

at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1282)

at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:283)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1192)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1089)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1002)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)

at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)

at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)

at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)

at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)

at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:113)

... 36 more

2015-6-7 10:06:10 org.apache.catalina.core.StandardContext start

严重: Error filterStart

很明显,上面的报错是struts2框架的报错信息,奇怪!我昨天晚上还可以访问这个工程的,怎么今天早上就不行了?难道是因为今天断网的原因?

我带着疑惑,寻找解决方法,web工程源码和部署都在本地电脑的,认真查看报错信息,Unable to load configuration. - Class: java.net.PlainSocketImpl,好像是没有在网络找到这个类的原因,struts2解析xml的时候要连struts.apache.org主机, 这个在断网的情况下肯定是不行的; 所以报错吧

后来我查看了struts.xml配置文件,发现struts.xml定义的版本和 struts2-core-2.1.6.jar里面的struts-default.xml版本不一致!!

struts-default.xml文件里面定义的<!DOCTYPE ...>如下:

<!DOCTYPE struts PUBLIC     "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"     "http://struts.apache.org/dtds/struts-2.1.dtd">

而struts.xm文件定义的<!DOCTYPE ...>为:

<!DOCTYPE struts PUBLIC     "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"     "http://struts.apache.org/dtds/struts-2.1.7.dtd">

注意struts-2.x.x后面的版本,报错的原因正是这里不一致所导致的!

解决方法:将struts-default.xml文件里面定义的<!DOCTYPE ...>复制粘贴覆盖到struts.xm文件定义的<!DOCTYPE ...>,以上报错的问题成功解决,关闭tomcat后,再重新启动tomcat,可以成功访问到web工程。

正文到此结束
Loading...