先来感慨下 真是解决的她吗的不容易啊 ~ 内牛满面 写出来和大家分享下 如果有需求的看看能不能帮到你
开始问题 我在做spring 项目的时候 突然间有需要 要拿着一台装着spring 项目的到户外去 去实地测试 需求来了 我想其他的局域网应用也应该有类似需求, 结果暴露出来一个项目中的bug问题 移植到linux 平台出错 刚开始的时候意识到时版本号的问题 结果自己修改后测试时候忘记提交 (悲剧的人 悲剧的命运) 于是另辟蹊径的我 转战ApplicationContent 的头文件
在有网络下测试
applicationContent.xml 头文件如下
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" default-lazy-init="true">
出现以下问题
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'. 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.xs.XMLSchemaValidator.handleStartElement(Unknown Source) at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.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.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
在网上查了半天又说该什么头文件的 但是 spring2.0 到 2.5 变化很多 文档定义文件就由DTD 转型为XSD了
于是我想将 XSD 下到本地来使用 突然有发现了JAR 包中有我需要的XSD 文件
修改配置文件如下
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-2.5.xsd http://www.springframework.org/schema/tx classpath:org/springframework/transaction/config/spring-tx-2.5.xsd http://www.springframework.org/schema/jee classpath:org/springframework/ejb/config/spring-jee-2.5.xsd http://www.springframework.org/schema/context classpath:org/springframework/context/config/spring-context-2.5.xsd" default-lazy-init="true">
修改完毕 测试成功 ~ 当时还认为只有这样配置才能完成 局域网类的spring 配置,
结果自己仔细查看了问题 才发现自己的spring jar是使用的myeclipse 导入的 版本是2.5.6 可是我spring 的头文件是从别的项目中拷贝过来的 3.0 包没有放入其中
这个才是最根本的原因
出现同类异常建议先检查jar 包版本是否匹配 惭愧惭愧