2016-01-23 205 views
1

我正在整合Hazelcast和Spring。它给我错误的架构。 检查了春天和榛子版,仍然不知道为什么。Hazelcast弹簧集成问题

春季版本:3.2.8 HazelCast版本:3.5

我的applicationContext:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:hz="http://www.hazelcast.com/schema/spring" 
    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.2.xsd 
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
         http://www.hazelcast.com/schema/spring http://hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd"> 

    <context:component-scan base-package="com.hazel.hazelcastSpringBasic" /> 

    <bean id="propertyConfigurer" 
     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
     <property name="locations"> 
      <list> 
       <value>classpath:/hazelcast-config.properties</value> 
      </list> 
     </property> 
    </bean> 

    <bean class="hazelcastSrpingBasic.TestBean" name="springTestBean"> 
     <property name="result" value="${value}" /> 
    </bean> 

    <hz:hazelcast id="instance"> 
     <hz:config> 
      <hz:group name="${name}" password="${password}" /> 
      <hz:properties> 
       <hz:property name="hazelcast.merge.first.run.delay.seconds">5</hz:property> 
       <hz:property name="hazelcast.merge.next.run.delay.seconds">5</hz:property> 
      </hz:properties> 
      <hz:network port="${defaultPort}" port-auto-increment="true"> 
       <hz:join> 
        <hz:multicast enabled="true" /> 
       </hz:join> 
      </hz:network> 
     </hz:config> 
    </hz:hazelcast> 

    <hz:client id="client"> 
     <hz:group name="${name}" password="${password}" /> 
     <hz:network> 
      <hz:member>127.0.0.1:5705</hz:member> 
     </hz:network> 
    </hz:client> 

    <hz:map id="map" instance-ref="instance" name="Map" lazy-init="false" /> 
    <hz:multiMap id="multiMap" instance-ref="instance" name="Multimap" /> 
    <hz:replicatedMap id="replicatedMap" instance-ref="instance" 
     name="ReplicatedMap" /> 
    <hz:queue id="queue" instance-ref="instance" name="Queue" /> 
    <hz:topic id="topic" instance-ref="instance" name="Topic" 
     depends-on="instance, client" /> 
    <hz:set id="set" instance-ref="instance" name="Set" /> 
    <hz:list id="list" instance-ref="instance" name="List" /> 
    <hz:executorService id="executorService" 
     instance-ref="instance" name="ExecutorService" /> 
    <hz:idGenerator id="idGenerator" instance-ref="instance" 
     name="IdGenerator" /> 
    <hz:atomicLong id="atomicLong" instance-ref="instance" 
     name="atomicLong" /> 
    <hz:atomicReference id="atomicReference" 
     instance-ref="instance" name="atomicReference" /> 
    <hz:countDownLatch id="countDownLatch" instance-ref="instance" 
     name="countDownLatch" /> 
    <hz:semaphore id="semaphore" instance-ref="instance" name="semaphore" /> 
    <hz:lock id="lock" instance-ref="instance" name="lock" /> 
</beans> 

错误我得到,而编译:提前

Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 2 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; systemId: http://hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd; lineNumber: 2; columnNumber: 35; s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '301 Moved Permanently'. 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243) 
    at org.springframework.context.support.GenericXmlApplicationContext.load(GenericXmlApplicationContext.java:115) 
    at org.springframework.context.support.GenericXmlApplicationContext.<init>(GenericXmlApplicationContext.java:69) 
    at hazelcastSpringBasic.SpringClient.main(SpringClient.java:26) 
Caused by: org.xml.sax.SAXParseException; systemId: http://hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd; lineNumber: 2; columnNumber: 35; s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw '301 Moved Permanently'. 
    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.opti.SchemaDOMParser.characters(Unknown Source) 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanContent(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.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source) 
    at org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source) 
    at org.apache.xerces.impl.xs.opti.SchemaDOMParser.parse(Unknown Source) 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source) 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source) 
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source) 
    at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(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.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:388) 
    ... 9 more 

感谢。

+0

在你的堆栈跟踪中,你有“301 Moved Permanently”=> Spring没有找到类路径中定义的xsd并尝试下载它。你可能有一个错误版本的hazelcast。 –

回答

4

它是否适合你,如果你改变了模式实例 从 http://www.hazelcast.com/schema/spring http://hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd"> 最后一行 http://www.hazelcast.com/schema/spring https://hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd"> 工作?

xsi:schemaLocation部分有问题。 对于第二个URL,上面引用的行缺少www

的XML文件中的第二url http://hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd 并应 http://www.hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd

+0

我觉得很傻。 :) 其实这确实给了我答案。 谢谢 – mikelee

2

您需要hazelcast-spring项目添加到您的类路径中。

<dependency> 
    <groupId>com.hazelcast</groupId> 
    <artifactId>hazelcast-spring</artifactId> 
    <version>3.5</version> 
</dependency> 
+0

已经添加。但谢谢你的回复。 我想我错过了非常小的东西。 – mikelee