问题描述
我的一个java web项目非常奇怪, 只要在家里编码启动的时候就偶尔报错。如下是错误信息是咋回事,在公司从未出现过这个问题,在家里已经出现过好几次了。Context initialization failedorg.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [C:UserspopcIdeaProjectsaaaa2015targetaaaa2015-0.0.1-SNAPSHOTWEB-INFclassesspringconfigurations.xml]; nested exception is java.net.ConnectException: Connection timed out: connectat org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:408)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93)at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4544)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5016)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:570)at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1352)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:601)at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:791)at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:598)at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:547)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:601)at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:791)at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1486)at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:96)at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1327)at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1419)at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:847)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:601)at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)at sun.rmi.transport.Transport$1.run(Transport.java:177)at sun.rmi.transport.Transport$1.run(Transport.java:174)at java.security.AccessController.doPrivileged(Native Method)at sun.rmi.transport.Transport.serviceCall(Transport.java:173)at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)at java.lang.Thread.run(Thread.java:722)Caused by: java.net.ConnectException: Connection timed out: connectat java.net.DualStackPlainSocketImpl.connect0(Native Method)at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)at java.net.Socket.connect(Socket.java:579)at java.net.Socket.connect(Socket.java:528)at sun.net.NetworkClient.doConnect(NetworkClient.java:180)at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)at sun.net.www.http.HttpClient.<init>(HttpClient.java:203)at sun.net.www.http.HttpClient.New(HttpClient.java:290)at sun.net.www.http.HttpClient.New(HttpClient.java:306)at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:995)at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:849)at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1299)at java.net.URL.openStream(URL.java:1037)at org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:796)at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:756)at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:267)at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(XMLDocumentScannerImpl.java:826)at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:333)at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:524)at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:580)at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:253)at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:201)at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)... 56 more十一月 07, 2014 5:56:59 下午 org.apache.catalina.core.StandardContext startInternalSEVERE: Error listenerStart十一月 07, 2014 5:56:59 下午 org.apache.catalina.core.StandardContext startInternalSEVERE: Context [/aaaa2015] startup failed due to previous errors
解决方案
context初始化失败,应该是你配置文件中 配置的dtd需要从网络上获取,获取不到 超时导致
解决方案二:
SAXBuilder和SAXReader解析xml时,会根据你xml文件DOCTYPE中的dtd验证文件路径,到网络上寻找该文件,当查找该文件失败或网络有异常时,就会抛出连接超时。看错误信息是spring读取配置文件,获取网络dtd文件连接超时抛出异常,spring默认使用jaxp.DocumentBuilderImpl解析xml,可以有多种方式解决这个问题最简单明了的方式是下载dtd到本地(下载路径即是你当前配置的路径),放到configurations.xml同一目标,并且修改configurations.xml的DOCTYPE如下模式<!DOCTYPE beans SYSTEM "spring-beans.dtd">当然更简单的方式是使用XSD代替dtd,spring的jar包中自带xsd定义文件,因此不需要联网也能执行验证
解决方案三:
time out把configurations.xml的内容发出来看下
解决方案四:
调高timeout,试试!
解决方案五:
连接timeout 了,就是连接超时了,网络问题
解决方案六:
网络问题吧,nested exception is java.net.ConnectException: Connection timed out: connect
解决方案七:
网络链接超时。