简体   繁体   English

在 spring bean.xml 中指定 xsd 的正确方法是什么

[英]What is the proper way to specify a xsd within a spring bean.xml

The beginning of my working bean.xml file looks like the following:我的工作 bean.xml 文件的开头如下所示:

<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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation=
  "http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

   http://www.springframework.org/schema/context
   http://www.springframework.org/schema/context/spring-context-4.2.xsd">

I happened to put the following URL http://www.springframework.org/schema/beans我碰巧把下面的网址http://www.springframework.org/schema/beans

which returned a list that looks like the following它返回了一个如下所示的列表

spring-beans-2.0.xsd
spring-beans-2.5.xsd
spring-beans-3.0.xsd
spring-beans-3.1.xsd
spring-beans-4.0.xsd
spring-beans-4.1.xsd
spring-beans-4.2.xsd
spring-beans.xsd

I downloaded spring-beans-4.2.xsd and spring-beans.xsd and did a diff on them.我下载了 spring-beans-4.2.xsd 和 spring-beans.xsd 并对它们进行了比较。 They seem to be identical.它们似乎完全相同。 Therefore, should I specify spring-beans-4.2.xsd or spring-beans.xsd.因此,我应该指定 spring-beans-4.2.xsd 还是 spring-beans.xsd。 Two concerns come to mind.我想到了两个问题。 1. If I use spring-beans.xsd then it would seem that I would always get the latest version. 1. 如果我使用 spring-beans.xsd 那么我似乎总是会得到最新版本。 This could be good if they are always backward compatible.如果它们始终向后兼容,这可能会很好。 2. Referring to #1 this could be bad because something may change in the .xsd and break my validation. 2. 参考 #1 这可能很糟糕,因为 .xsd 中的某些内容可能会发生变化并破坏我的验证。

My feeling is to lock in the .xsd with spring-beans-4.2.xsd and change the bean.xml file when I am ready.我的感觉是用 spring-beans-4.2.xsd 锁定 .xsd 并在我准备好时更改 bean.xml 文件。 Thoughts on this observation would be greatly appreciated.对这一观察的想法将不胜感激。

我宁愿指定特定版本,因为有时存在依赖项冲突问题,因此http://www.springframework.org/schema/beans/spring-beans-4.2.xsd应该可以。

The advice for some time now has been to use the versionless schema, especially now Spring 5 has been released, which doesn't have a versioned schema (See [SPR-13499] )一段时间以来的建议是使用无版本模式,尤其是现在 Spring 5 已经发布,它没有版本模式(参见[SPR-13499]

A more complete answer can be found at Spring configuration XML schema: with or without version?可以在Spring configuration XML schema: with or without version? 中找到更完整的答案

THis question should have been closed as a duplicate of that question, but it's too late to do that now.这个问题应该作为该问题的副本而关闭,但现在这样做已经太晚了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CDI-正确的bean.xml格式是什么? - CDI - what is the correct bean.xml format? 在春季使用bean.xml时发生Classdefnotfound异常 - Classdefnotfound exception while using bean.xml in spring 在Spring的bean.xml中将bean的id设置为空时发生奇怪的异常 - Strange exception when id of the bean is set empty in spring's bean.xml 在项目中指定XSD schemaLocation的正确或适当方法是什么? - What's the correct or proper way to specify XSD schemaLocation across projects? 加载应用程序上下文文件Bean.xml - Loading Application Context File Bean.xml 如何从bean.xml获取bean值 - How to I get bean value from bean.xml 添加了新的bean.xml并获取具有根本原因的类路径资源[Spring-Mail.xml]无法打开,因为它不存在] - Added new bean.xml and get class path resource [Spring-Mail.xml] cannot be opened because it does not exist] with root cause 在 spring 集成中将 XML 转换为 Java 对象的正确方法是什么? - What is the proper way to convert XML to Java objects in spring integration? 在@Configuration中提供对spring @Bean的依赖关系的正确方法 - Proper way of providing dependency to spring @Bean in @Configuration 从Tapestry Page类中访问EJB3 Bean的正确方法是什么? - What's the proper way to access an EJB3 Bean from within a Tapestry Page class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM