我正在集成 Hazelcast 和 Spring。它给我关于模式的错误。 检查了 spring 和 hazelcast 版本,仍然不确定为什么。
Spring Version : 3.2.8 HazelCast Version : 3.5
我的应用程序上下文:
<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
提前致谢。
最佳答案
如果您更改架构实例的最后一行,它对您有用吗
从
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
关于java - Hazelcast Spring 集成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34964479/