Hazelcast集成Spring,解析hazelcast定义出错

在Spring中定义Hazelcast配置:

 

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:hz="http://www.hazelcast.com/schema/spring"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context.xsd
                http://www.hazelcast.com/schema/spring
                http://www.hazelcast.com/schema/spring/hazelcast-spring.xsd">

 <context:annotation-config />

 <hz:hazelcast id="instance">
  <hz:config>
   <hz:network port="5701" port-auto-increment="true">
    <hz:join>
     <hz:multicast enabled="true" 
      multicast-group="224.2.2.3" 
      multicast-port="54327" 
      multicast-time-to-live="32" 
      multicast-timeout-seconds="2" />
    </hz:join>
   </hz:network>
   
   <hz:group name="pushcoregroup" password="password" />
  
    
  </hz:config>
 </hz:hazelcast>

</beans>

 

 

启动时,程序报错:

Caused by: org.xml.sax.SAXParseException; lineNumber: 25; columnNumber: 57; cvc-complex-type.2.4.a: 发现了以元素 'hz:group' 开头的无效内容。应以 '{"http://www.hazelcast.com/schema/spring":partition-group, "http://www.hazelcast.com/schema/spring":executor-service, "http://www.hazelcast.com/schema/spring":queue, "http://www.hazelcast.com/schema/spring":map, "http://www.hazelcast.com/schema/spring":cache, "http://www.hazelcast.com/schema/spring":multimap, "http://www.hazelcast.com/schema/spring":list, "http://www.hazelcast.com/schema/spring":set, "http://www.hazelcast.com/schema/spring":topic, "http://www.hazelcast.com/schema/spring":jobtracker, "http://www.hazelcast.com/schema/spring":replicatedmap, "http://www.hazelcast.com/schema/spring":listeners, "http://www.hazelcast.com/schema/spring":serialization, "http://www.hazelcast.com/schema/spring":security, "http://www.hazelcast.com/schema/spring":member-attributes, "http://www.hazelcast.com/schema/spring":services}' 之一开头。
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
 at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
 at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
 at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:458)
 at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3237)
 at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1796)
 at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.emptyElement(XMLSchemaValidator.java:766)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:356)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
 at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
 at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
 at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
 at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
 at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
 at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:429)
 at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
 ... 14 more

 

 

 

通过排查后,发现http://hazelcast.com/schema/spring/hazelcast-spring-3.4.xsd中定义了元素出现的顺序,

 

<xs:element name="config">
<xs:complexType>
<xs:complexContent>
<xs:extension base="hazelcast-bean">
<xs:sequence>
<xs:element name="spring-aware" type="spring-aware" minOccurs="0" maxOccurs="1"/>
<xs:element name="instance-name" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="group" type="group" minOccurs="0" maxOccurs="1"/>
<xs:element name="license-key" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="management-center" type="management-center" minOccurs="0" maxOccurs="1"/>
<xs:element name="properties" type="properties" minOccurs="0" maxOccurs="1"/>
<xs:element name="wan-replication" type="wan-replication" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="network" type="network" minOccurs="0" maxOccurs="1"/>
<xs:element name="partition-group" type="partition-group" minOccurs="0" maxOccurs="1"/>
<xs:element name="executor-service" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="queue" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="map" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="cache" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="multimap" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="list" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="set" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="topic" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="jobtracker" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="replicatedmap" minOccurs="0" maxOccurs="unbounded">...</xs:element>
<xs:element name="listeners" type="listeners" minOccurs="0" maxOccurs="1"/>
<xs:element name="serialization" type="serialization" minOccurs="0" maxOccurs="1"/>
<xs:element name="security" type="security" minOccurs="0" maxOccurs="1"/>
<xs:element name="member-attributes" minOccurs="0" maxOccurs="1">...</xs:element>
<xs:element name="services" type="services" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="data-serializable-factories">

 

 
 

其中xs:sequence指示器规定了各个元素出现的顺序,要求group出现在network的前面,于是,把配置改成这样:

<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
 xmlns:hz="http://www.hazelcast.com/schema/spring"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context.xsd
                http://www.hazelcast.com/schema/spring
                http://www.hazelcast.com/schema/spring/hazelcast-spring.xsd">

 <context:annotation-config />

 <hz:hazelcast id="instance">
  <hz:config>
   <hz:group name="pushcoregroup" password="password" />
  
   <hz:network port="5701" port-auto-increment="true">
    <hz:join>
     <hz:multicast enabled="true" 
      multicast-group="224.2.2.3" 
      multicast-port="54327" 
      multicast-time-to-live="32" 
      multicast-timeout-seconds="2" />
    </hz:join>
   </hz:network>
   
   
  
    
  </hz:config>
 </hz:hazelcast>

</beans>

 

 

 

 

 

问题就解决了!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值