gpt4 book ai didi

xml - Spring 配置文件如何针对 Spring bean XSD 进行验证?

转载 作者:数据小太阳 更新时间:2023-10-29 02:09:07 31 4
gpt4 key购买 nike

这可能是一个基本的 XML 查询,但我在 XML 方面有点薄弱。因此这个查询。

考虑Spring配置中的标签

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
default-autowire="byName">

这里 spring beans 的 XSD 位于 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 位置.我的查询如下。

  1. 它是否通过互联网转到 XSD 以执行验证?

  2. 如果上述问题的答案是肯定的,它什么时候引用包org.springframework.beans.factory.xml中的spring-beans jar中的XSD?当我离线工作时是这样吗?

  3. 假设它引用 jar 中的 XSD,它如何找到它?配置知道的唯一 XSD 位置是 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd .这不是指向 jar 中某些内容的文件路径。它会预加载 XSD 吗?如果是这样,这是谁干的? bean 工厂?

最佳答案

在 spring jar 中有名为

META-INF/spring.schemas

这些提供了从命名空间到可以找到模式的路径(在类路径上)的映射。

这里是 spring-beans-3.2.1.RELEASE.jar 的例子

http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.2.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.2.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.2.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.2.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-3.2.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.2.xsd

类 org.springframework.beans.factory.xml.PluggableSchemaResolver 查看 spring.schemas 文件以找到模式文件的位置。

关于xml - Spring 配置文件如何针对 Spring bean XSD 进行验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8723212/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com