Spring配置XML架构:有没有版本? [英] Spring configuration XML schema: with or without version?

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

问题描述

我是Spring的新手。有一件事让我感到困惑的是,有时候我会看到带有版本化模式的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-beans spring-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?

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

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 实际建立链接的文件)。
此外,在线提供的文件也以相同的方式构建(请参阅 gradle构建中的schemaZip目标)。

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天全站免登陆