java异常:org.xml.sax.SAXParseException: Document root element "beans", must match

 用java在开发一个监控项目的时候,Eclipse里面运行的很正常,但是打包用外部的Tomcat的时候就报错,显然jar包问题,错误如下:

org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
 at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
 at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
 at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.rootElementSpecified(Unknown Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
 at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
 at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
 at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
 at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
 at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:222)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
 at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:126)
 at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
 at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269)
 at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
 at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
 at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
 at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1654)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
 at java.util.concurrent.FutureTask.run(FutureTask.java:138)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
 at java.lang.Thread.run(Thread.java:619)

 

百度搜了一下,有人说要在spring加载的文件头加上




……

 
其实是不准确的 ,然后我查看了一下打包项目后的jar包,发现里面有两个spring的jar包,分别是
spring-1.2.6.jar
spring-core-3.1.1.RELEASE.jar
明显是有问题的,版本就不一致了,这里我们就要看spring的xml文件了


 
很明显引用的都是3.0版本的,所有删掉spring-1.2.6.jar ,再运行Tomcat , Ok ,正常了,当然别忘了把项目里的jar包引用去掉。

你可能感兴趣的:(java疑难杂症,java,spring异常)