Spring 配置 XML 模式:有或没有版本? [英] Spring configuration XML schema: with or without version?

查看:27
本文介绍了Spring 配置 XML 模式:有或没有版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Spring 的新手.让我感到困惑的一件事是,有时我会看到带有版本模式的 XML 配置文件,但有时会看到带有非版本模式的 XML 配置文件.例如,有时我会看到类似

I am new to Spring. One thing confuses me is that sometimes I see XML configuration files with versioned schemas, yet sometimes with non-versioned ones. For example, sometimes I see something like

<?xml version="1.0" encoding="UTF-8"?>
<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-4.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <context:annotation-config/>

    <context:component-scan base-package="base.package"/>

</beans>

有时是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<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.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

    <context:annotation-config/>

    <context:component-scan base-package="base.package"/>

</beans>

请注意,两个示例中的 spring-beansspring-context 模式是不同的.

Note that the spring-beans and spring-context schemas are different in the two examples.

那么,我的问题是,您会使用哪种样式,为什么?特别是,版本化模式将来是否会变得不可用,当 Spring 更新模式时,非版本化模式是否会与当前应用程序保持兼容?

So, my question is, which style would you use and why? In particular, will the versioned schema become unavailable in the future, and will the non-versioned schema keep compatible with a current application when Spring updates the schema?

一个附带问题是,我在哪里可以找到版本化 spring 模式的列表?

A side question is, where can I find a list of the versioned spring schemas?

非常感谢!

推荐答案

建议使用无版本"XSD,因为它们映射到您在应用程序中使用的框架的当前版本.

It is recommended to use the "versionless" XSDs, because they're mapped to the current version of the framework you're using in your application.

>

应用程序和工具不应尝试从 Web 获取这些 XSD,因为这些架构包含在 JAR 中.如果出现这种情况,通常意味着您的应用正在尝试使用比您正在使用的框架版本更新的 XSD,或者您的 IDE/工具未正确配置.

Applications and tools should never try to fetch those XSDs from the web, since those schemas are included in the JARs. If they do, it usually means your app is trying to use a XSD that is more recent than the framework version you're using, or that your IDE/tool is not properly configured.

据我所知,只有一种情况您希望使用特定的 XSD 版本:尝试使用在较新版本中已弃用/修改的 XML 属性时.至少可以说,这种情况并不经常发生.

To my knowledge, there's only one case where you'd want to use specific XSD versions: when trying to use a XML attribute that's been deprecated/modified in a more recent version. That doesn't happen often to say the least.

无论如何,Spring 团队应该放弃 Spring 5.0 的版本化架构,请参阅 SPR-13499.

Anyway the Spring team should drop the versioned schemas for Spring 5.0, see SPR-13499.

更多关于无版本 == 当前版本"的信息:

那些 XSD 文件包含在 Spring JAR 中——无版本"XSD 在构建期间映射到最新版本(请参阅 spring.schemas 实际建立该链接的文件).此外,在线可用的文件以相同的方式构建(参见 "schemaZip" 目标在 gradle 构建中).

Those XSD files are included in Spring JARs - the "versionless" XSD is mapped to the latest version during the build (see the spring.schemas files that actually make that link). Also, the files available online are built the same way (see the "schemaZip" target in the gradle build).

这篇关于Spring 配置 XML 模式:有或没有版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆