【问题标题】:XML schema location best practicesXML 模式位置最佳实践
【发布时间】:2011-01-25 17:49:51
【问题描述】:

在看到一些更神秘的错误消息后,我意识到它们可能是由于此处存在虚假 URI:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:cxf="http://activemq.apache.org/camel/schema/cxfEndpoint"    
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
        http://activemq.apache.org/camel/schema/spring
        http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
        http://activemq.apache.org/camel/schema/cxfEndpoint
        http://activemq.apache.org/camel/schema/cxf/cxfEndpoint.xsd
        http://cxf.apache.org/jaxws 
        http://cxf.apache.org/schemas/jaxws.xsd
        ">

参考在线模式是一种好习惯吗?

从上面举例:

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

工作正常,当您没有互联网问题并且 springframework.org 启动等时,这一切都很可爱而且很好。但是,从上面来看,还有:

http://activemq.apache.org/camel/schema/cxf/cxfEndpoint.xsd

给出:

"Oops! This link appears to be broken"

确实糟糕。

关于在项目中引用架构的 URI 的最佳做法是什么?

额外问题:Eclipse 为何不实时抱怨断开的链接? (IntelliJ IDEA 做的对吗!?)

【问题讨论】:

  • 这些 URI 引用的模式是 SPOF 吗? (单点故障)

标签: java xsd uri


【解决方案1】:

Spring 在启动容器时不会通过网络加载模式 - 有一种嵌入 schemas within the jar files of Spring 的机制,Spring 使用这些内置模式来验证 xml。这也适用于所有自定义命名空间。

Eclipse 可能会抱怨,因为 Eclipse 会根据架构 URI 下载架构,而架构 URI 可能不会托管在网络上,就像您的情况一样,还有一种方法可以在 Eclipse 首选项中缓存自定义架构。

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 2014-03-25
    • 2017-09-01
    • 1970-01-01
    相关资源
    最近更新 更多