java - 理解 xml 模式定位

标签 java xml spring spring-mvc

我正在尝试了解以下 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/mvcschemaLocation 属性以在我的 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/

相关文章:

java - @SpringBootTest + @BeforeAll

java - 将 JSON 对象放入 RESTful 服务器的正确方法

java - 无法在 Android Studio 上将 DateTime 插入 SQLite

html - 调试 'Error loading stylesheet: XPath parse failure: Name or Nodetype test expected:'

xml - XPath 中//*[*] 和//*[.] 有什么区别?

java - spring security 3.0.3配置错误

java - Spring 4 中 ExpressionEvaluationUtils 的替代方案

Java : Open file in default editor and jump to line number

Java 西蒙说

android - 如何在抽屉导航中放置 2 个 ListView?