XML 架构位置最佳实践
在看到一些更神秘的错误消息后,我意识到它们可能是由于此处出现的虚假 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 做得对吗!?)
After seeing quite some more cryptic error message, I realize they may be due to bogus URIs present here:
<?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
">
Is it good practice to refer to online schemas?
From the above, for example:
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
works fine, which is all cute and well when you've got no Internet issue and when springframework.org is up etc. but then, from the above, there's also:
http://activemq.apache.org/camel/schema/cxf/cxfEndpoint.xsd
which gives:
"Oops! This link appears to be broken"
Oops indeed.
What are best practice regarding URIs referring to schema in a project?
Bonus question: how comes Eclipse doesn't complain in real-time about the broken links? (IntelliJ IDEA does it right!?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Spring 在启动容器时不会通过网络加载架构 - 有一种机制可以嵌入 Spring jar 文件中的 schema,Spring 使用这些内置 schema 来验证 xml。这也适用于所有自定义名称空间。
Eclipse 可能会抱怨,因为 Eclipse 根据架构 URI 下载架构,该架构可能不是通过网络托管的,就像您的情况一样,也有一种方法可以在 Eclipse 首选项中缓存自定义架构。
Spring does not load the schemas over the net when starting up the container - there is a mechanism to embed the schemas within the jar files of Spring, and Spring uses these built-in schemas to validate the xml. This is applicable for all custom namespaces too.
Eclipse may complain, because Eclipse downloads the schemas based on the schema URI, which may not be hosted over the net, like in your case, there is a way to cache custom schemas within the Eclipse preferences also.
看一下 CatalogResolver: http://xml.apache.org/commons/components/apidocs/resolver/org/apache/xml/resolver/tools/CatalogResolver.html
可能有帮助。
Take a look at the CatalogResolver: http://xml.apache.org/commons/components/apidocs/resolver/org/apache/xml/resolver/tools/CatalogResolver.html
May be it helps.