我正在尝试了解以下 xml 文件的 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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
</beans>
我没有得到这里指定的 schemaLocation。例如,为什么我应该同时添加 xmlns:mvc = "http://www.springframework.org/schema/mvc"
和 http://www.springframework.org/schema/mvc
到 schemaLocation
属性以在我的 spring 配置文件中使用 mvc:xxx_something_xxx
?
我只是想了解我每次开始创建spring-mvc应用程序时所做的事情,而不是不理解就从google复制粘贴。
最佳答案
xmlns
定义了一个命名空间。如果你想使用 mvc:xxx
你必须定义什么是 mvc
命名空间。
xsi:schemaLocation
定义 XSD(用于 XML 验证)所在的位置。
如果我没记错的话,latest 不是强制性的,但如果您不设置它,那么您可能会在不注意的情况下使用无效的 XML。
相关于:
关于java - 理解 xml 模式定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27720806/