2013-02-15 72 views
0

我通常会得到这样的错误不是当上线:没有声明可以为元素(XML架构)中找到

org.xml.sax.SAXParseException; lineNumber: 55; columnNumber: 33; schema_reference.4: Failed to read schema document 'http://www.hazelcast.com/schema/spring/hazelcast-spring-2.1.xsd', 
because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 

Caused by: java.net.ConnectException: Connection timed out: connect 

...no declaration can be found for element 'hz:hazelcast'. 

什么解决的办法,使其不必连接到互联网只是为了这个每一次。

回答

3

你不会在你的问题中确切地说明你是如何加载需要这个模式的XML文件的,但是它的名字看起来与Spring bean配置有关。 Spring为组件提供了一种机制,这些组件提供了自己的模式来将这些模式捆绑到他们的JAR文件中,所以他们不需要从互联网中获取它们。这涉及命名META-INF/spring.schemas在JAR文件中的java.util.Properties格式文件,其中包含映射HTTP URL到本地路径(在JAR文件中)系,例如

http\://www.hazelcast.com/schema/spring/hazelcast-spring-2.1.xsd=hazelcast-spring-2.1.xsd 

(来自hazelcast-spring-2.1.3.jar)。

所以我怀疑这里发生了什么是你指的是与你实际使用的hazelcast版本不同的模式版本,这意味着你请求的模式没有在spring.schemas目录中列出,因此它必须到互联网上下载它。例如,如果您有hazelcast-spring-2.5.jar,则需要使用xsi:schemaLocation中的匹配http://www.hazelcast.com/schema/spring/hazelcast-spring-2.5.xsd

+0

我明白了,那可能是问题所在 – xybrek 2013-02-15 17:55:44

1

下载xsd并将其保存在您的项目中。使用下面的代码访问以下

JAXBContext context = JAXBContext.newInstance(<your>.class); 
Unmarshaller jaxbUnMarshaller = context.createUnmarshaller(); 


SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); 
URL tmpurl = getClass().getClassLoader().getResource("file.xsd"); 
Schema s = schemaFactory.newSchema(tmpurl); 
jaxbUnMarshaller.setSchema(s); 
0

复制的XSD XSD到WEB-INF /并给予URI作为/WEB-INF/xsdname的.xsd中,你是在XML文件中使用模式。

相关问题