java Spring bean DTD 和 XMLNS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17822466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 15:07:57  来源:igfitidea点击:

Spring beans DTD and XMLNS

javaspringjavabeans

提问by user962206

When i am creating a spring project I always have problem with XLMNS. what is exactly XMLNS? what are these actually?

当我创建一个 spring 项目时,我总是遇到 XLMNS 问题。什么是 XMLNS?这些实际上是什么?

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 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.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"

And where can I get the references for these? (resource of xmlns:xsi and xsi:schemeLocation.) is there any online manual for these? I can't seem to find them.

我在哪里可以获得这些参考资料?(xmlns:xsi 和 xsi:schemeLocation 的资源。)有没有这些的在线手册?我似乎找不到他们。

NOTEWhen I said references I meant the proper urls for them

注意当我说引用时,我指的是它们的正确网址

UPDATED

更新

Where can I see the XML namespaces for Spring beans, Spring Transactions, Spring MVC and such? and its schema locations?

我在哪里可以看到 Spring bean、Spring Transactions、Spring MVC 等的 XML 命名空间?及其架构位置?

回答by Solubris

There is a good explanation here: what is the use of xsi:schemaLocation?

这里有一个很好的解释: xsi:schemaLocation 有什么用?

Here is springs docs on xsd config: http://static.springsource.org/spring/docs/current/spring-framework-reference/html/xsd-config.html

这是关于 xsd 配置的 springs 文档:http: //static.springsource.org/spring/docs/current/spring-framework-reference/html/xsd-config.html

NOTE: spring now recommend not to include the version number in the xsd unless specifically required, so you should have:

注意:spring 现在建议不要在 xsd 中包含版本号,除非特别需要,所以你应该:

xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans.xsd"

and not:

不是

xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"

"xmlns" defines the name space for the current element.

“xmlns”定义当前元素的命名空间。

"xmlns:aop" defines the name space for elements within the current element, that have a prefix of "aop:"

“xmlns:aop”定义当前元素中元素的命名空间,前缀为“aop:”

回答by JQ-

These lines set up the namespaces for your XML document. Depending on what tags you are using in your XML file, you'll need the namespaces at the top (and references to the correct schemas) in order for the XML to be valid.

这些行为您的 XML 文档设置命名空间。根据您在 XML 文件中使用的标签,您需要顶部的命名空间(以及对正确模式的引用)以使 XML 有效。

For example, if you are using the <aop/>tag in your bean definitions, you will need to reference the aop schema at the top of the file: xmlns:aop="http://www.springframework.org/schema/aop"If you aren't using that tag, you don't need that there.

例如,如果您<aop/>在 bean 定义中使用标签,则需要引用文件顶部的 aop 模式:xmlns:aop="http://www.springframework.org/schema/aop"如果您不使用该标签,则不需要该标签。

For any namespaces you import, make sure you add a reference to the schema in the "xsi:schemaLocation" tag, like this: xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

对于您导入的任何命名空间,请确保在“xsi:schemaLocation”标记中添加对架构的引用,如下所示: xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

I would recommend checking out a sample Spring application since it should have the bare minimum that you need to get something running.

我建议查看一个示例 Spring 应用程序,因为它应该具有运行某些东西所需的最低限度。

回答by Nizzo

As far as answering the 'where is it documented', I think it depends per project. In the case of Spring, the project documentation does contain a reference to this information. As an example, check out the xsd-config section for Spring Framework 3.2.x: Appendix E. XML Schema-based configuration

至于回答“它记录在哪里”,我认为这取决于每个项目。对于 Spring,项目文档确实包含对此信息的引用。例如,查看 Spring Framework 3.2.x 的 xsd-config 部分:附录 E. 基于 XML 模式的配置