【问题标题】:cvc-elt.1: Cannot find the declaration of element 'hazelcast'cvc-elt.1:找不到元素“hazelcast”的声明
【发布时间】:2019-08-12 06:56:56
【问题描述】:

我正在尝试使用 Spring 配置 Hazelcast。 我正在为 Hazelcast 的 xml 文件配置使用单独的文件,我检查了我在 XML 中配置的 xsd,它包含“hazelcast”元素,还根据 xsd 中的命名空间规范进行了配置,还添加了 3.3 版本的 hazelcast、hazelcast-all 和 hazelcast -春天。

我检查了 xsd 文件 - http://www.hazelcast.com/schema/config hazelcast-config-3.3.xsd ,我可以打开并找到其中的 hazelcast 元素。

你可以在这里参考 hazlecast xml - https://dzone.com/articles/configuring-hazelcast-within

<hazelcast  
xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.3.xsd"

           xmlns="http://www.hazelcast.com/schema/config"

           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >      
    <group>
        <name>hazelcast</name>
        <password>12345</password>
    </group>
    <properties>
        <property name="hazelcast.logging.type">slf4j</property>
        <property name="hazelcast.jmx">true</property>
        <property name="hazelcast.jmx.detailed">true</property>
    </properties>

    <management-center enabled="false">http://localhost:8080/hazelcast</management-center>



    <map name="HttpRequestsCache">
        <time-to-live-seconds>600</time-to-live-seconds>
        <max-size>1000</max-size>
    </map>






</hazelcast>

但出现错误 -

在这一行找到多个注释: - 无法找到架构命名空间“http://www.hazelcast.com/”的元素“hazelcast”的 Spring NamespaceHandler 架构/配置' - cvc-elt.1:找不到元素“hazelcast”的声明。 - schema_reference.4:无法读取架构文档“hazelcast-config-3.3.xsd”,因为

1) 找不到文件; 2) 文件无法读取; 3) 文档的根元素不是。

【问题讨论】:

    标签: xml spring hazelcast


    【解决方案1】:

    您的 XML 在帖子中的格式不正确,但我怀疑问题出在

    xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.3.xsd"
    

    应该是

    xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.3.xsd"
    

    如果您要将 Hazelcast 添加到项目中,最好选择比 3.3 更新的版本。当前是3.12。

    Spring 的大量工作示例 here 可作为基础,并带有正确的 XML。

    【讨论】:

    • 嗨,尼尔,感谢您的回复。我已经在 3.10 版本中尝试过前面提到的语法,但没有成功。然后我决定尝试使用较低版本,因为我们的 Spring 版本较旧 3.1.1.RELEASE 。让我尝试您在 URL 中提到的其他配置。
    • 我用 3.7 版本的 xmls 配置了项目并且运行良好。参考:baeldung.com/java-hazelcast
    • 对不起,在构建项目后的一段时间内,我意识到问题已解决但仍然没有。
    • 你能发布新的 XML 吗?如果它工作然后停止工作,则可能是间歇性网络问题,因此日志中的错误消息也将很有用。也许作为一个新问题,并通过评论链接到它。
    • 谢谢,我在 classpath 和 web.xml 中使用的相同 xml 声明为 classpath 而不是引用路径,并且没有任何 xml 错误问题得到解决。
    【解决方案2】:

    在 Eclipse 2020-06 中出现同样的错误,使用“https”URL 为我修复了它:

    <hazelcast xsi:schemaLocation="https://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd"
           xmlns="https://www.hazelcast.com/schema/config"
           xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-05
      • 2020-05-08
      • 2015-11-25
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多