最近遇到一个奇葩的问题,我们的后台Dubbo服务已经和Spring 4.0.2.RELEASE版本集成,因为需要和一个第三方服务提供方对接,而对方提供的接口是web Service的,而且使用的框架是xfire。我们的技术对接童鞋,按照对方提供的技术文档进行代码编写,在pom.xml中添加了一段依赖导入相关需要的jar包,配置如下:
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-all</artifactId>
<version>1.2.6</version>
</dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-all</artifactId>
<version>1.2.6</version>
</dependency>
然后当代码开发已经写得差不多了,在调试的时候就出现一个奇葩问题,老是报一个错org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 96; Document root element “beans”, must match DOCTYPE root “null”.
具体的报错信息如下:
sh-3.2# sh bin/startDev.sh
Listening for transport dt_socket at address: 9555
[com.alibaba.dubbo.common.logger.LoggerFactory] - using logger: com.alibaba.dubbo.common.logger.log4j.Log4jLoggerAdapter
[com.alibaba.dubbo.container.Main] - [DUBBO] Use container type([spring]) to run dubbo serivce., dubbo version: 2.4.9, current host: 127.0.0.1
[org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from URL [file:/Users/lichaoqiang/wdzj/svn_new/projects/credit-thirdpartzx/trunk/target/wdzj-thirdpartzx-1.1.1-SNAPSHOT-pack/thirdpartzx/conf/dubbo/provider.xml]
org.springframework.beans.factory.BeanDefinitionStoreException: Line 5 in XML document from URL [file:/Users/lichaoqiang/wdzj/svn_new/projects/credit-thirdpartzx/trunk/target/wdzj-thirdpartzx-1.1.1-SNAPSHOT-pack/thirdpartzx/conf/dubbo/provider.xml] is invalid; nested exception is org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 96; 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.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:81)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
at com.alibaba.dubbo.container.spring.SpringContainer.start(SpringContainer.java:50)
at com.alibaba.dubbo.container.Main.main(Main.java:80)
经过查证相关资料,发现原来有一个xfire-all导入的一个jar包中依赖了一个1.2.6版本的spring的jar包,而我们的项目采用的Spring的版本就是4.0.2.RELEASE,所以就有冲突。
解决办法就是把spring相关的jar包exclusion。具体的办法是修改pom.xml:
<dependency>
<groupId>org.codehaus.xfire</groupId>
<artifactId>xfire-all</artifactId>
<version>1.2.6</version>
<exclusions>
<exclusion>
<artifactId>xfire-spring</artifactId>
<groupId>org.codehaus.xfire</groupId>
</exclusion>
</exclusions>
</dependency>