Spring 模式文件夹和 Spring XML 命名空间
Spring schema folder & Spring XML namespaces
我正在寻找我们应该如何在 Spring bean XML 定义中确定名称空间的符号。我猜它们在 Spring 架构文件夹中,但我找不到它。例如,c:
、p:
、util:
、..在XML bean配置中是什么?
在哪里可以找到每个命名空间的架构?例如,我如何知道我是否应该在 xmlns:p="http://www.springframework.org/schema/p"
中使用 http://www.springframework.org/schema/p
,其他名称空间在哪里以及如何找到它们?
您可以自行选择符号(p
、util
、jee
、beans
、...)。这些是名称空间,它们通过添加 xmlns
属性来工作,例如:
<beans xmlns:util="http://www.springframework.org/schema/util">
<!-- Content -->
</beans>
在这种情况下,我们说过 util:
将由 util 模式使用,因此您必须使用 <util:properties>
来访问此命名空间中的内容。但你也可以说 xmlns:foobar="http://www.springframework.org/schema/util"
在这种情况下你可以使用 <foobar:properties>
.
但是您还需要使用 xsi:schemaLocation
:
提供该命名空间的 XSD 的位置
<beans xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Content -->
</beans>
在这种情况下,http://www.springframework.org/schema/util
的 XSD 在 http://www.springframework.org/schema/util/spring-util.xsd 可用。 http://www.springframework.org/schema/util
部分只是一个标签,也可以选择。唯一必须匹配的是 XSD 架构。
有关 XML 个命名空间的更多信息,您应该查看 this question and its answers。
可以在其文档 (33. XML Schema-based configuration) 中找到具有 Spring 的常见 XML 模式列表。但是,这些仅列出了核心模式。一些项目(如 Spring Web 服务,...)有自己的命名空间,如:
- http://www.springframework.org/schema/web-services/web-services.xsd
- http://www.springframework.org/schema/oxm/spring-oxm.xsd
- ...
您可以通过访问 Index of /schema. However, like I mentioned, most of these are only used for specific Spring projects, don't just import them, read the specific documentation to find out what you need. The documentation about the constructor namespace (c:
) can be found in 7. The IoC container.
找到整个列表
我正在寻找我们应该如何在 Spring bean XML 定义中确定名称空间的符号。我猜它们在 Spring 架构文件夹中,但我找不到它。例如,c:
、p:
、util:
、..在XML bean配置中是什么?
在哪里可以找到每个命名空间的架构?例如,我如何知道我是否应该在 xmlns:p="http://www.springframework.org/schema/p"
中使用 http://www.springframework.org/schema/p
,其他名称空间在哪里以及如何找到它们?
您可以自行选择符号(p
、util
、jee
、beans
、...)。这些是名称空间,它们通过添加 xmlns
属性来工作,例如:
<beans xmlns:util="http://www.springframework.org/schema/util">
<!-- Content -->
</beans>
在这种情况下,我们说过 util:
将由 util 模式使用,因此您必须使用 <util:properties>
来访问此命名空间中的内容。但你也可以说 xmlns:foobar="http://www.springframework.org/schema/util"
在这种情况下你可以使用 <foobar:properties>
.
但是您还需要使用 xsi:schemaLocation
:
<beans xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!-- Content -->
</beans>
在这种情况下,http://www.springframework.org/schema/util
的 XSD 在 http://www.springframework.org/schema/util/spring-util.xsd 可用。 http://www.springframework.org/schema/util
部分只是一个标签,也可以选择。唯一必须匹配的是 XSD 架构。
有关 XML 个命名空间的更多信息,您应该查看 this question and its answers。
可以在其文档 (33. XML Schema-based configuration) 中找到具有 Spring 的常见 XML 模式列表。但是,这些仅列出了核心模式。一些项目(如 Spring Web 服务,...)有自己的命名空间,如:
- http://www.springframework.org/schema/web-services/web-services.xsd
- http://www.springframework.org/schema/oxm/spring-oxm.xsd
- ...
您可以通过访问 Index of /schema. However, like I mentioned, most of these are only used for specific Spring projects, don't just import them, read the specific documentation to find out what you need. The documentation about the constructor namespace (c:
) can be found in 7. The IoC container.