【问题标题】:spring-beans.xsd does not define "local". Why?spring-beans.xsd 没有定义“本地”。为什么?
【发布时间】:2014-01-30 00:11:20
【问题描述】:

几乎每个spring项目都使用spring-beans.xsd(指它更准确)。但是,如果您查看文件 http://www.springframework.org/schema/beans/spring-beans.xsd,您会发现它是 3.2 版,并且没有属性“local”的定义。

更有趣的是,http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 确实定义了“本地”。

此外,由于 spring.schema 将文件从 jar (org/springframework/beans/factory/xml/spring-beans-3.2.xsd) 中拉出,我认为任何项目都不会编译或运行时问题。

另一方面,我认为 Eclipse 的 xml 验证器仅使用 Internet 链接并显示 xml 错误,更具体地说:

"cvc-complex-type.3.2.2: 属性'local'不允许出现在元素'ref'中"

这是一个错误吗?

编辑: 根据要求,这是我的弹簧头:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:oxm="http://www.springframework.org/schema/oxm" xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">

编辑 2:这里是我使用本地的地方

    <bean id="bar" 
    class="org.springframework.batch.item.support.CompositeItemWriter">
    <property name="delegates">
        <list>
            <ref local="foo" />
        </list>
    </property>
</bean>
<bean id="foo" class="java.lang.String" />

【问题讨论】:

  • 请向我们展示您尝试使用 Eclipse 验证的 XML。编辑您的问题。
  • 如果你去springframework.org/schema/beans .. 你会发现版本根本不重要。
  • @Ashish 你是什么意思版本无关紧要?这甚至不是我的问题。我说的是两个文件,在这种情况下,spring-beans.xsd 和 spring-beans-3.2.xsd 说它们是相同的版本,但一个定义了“本地”属性,另一个没有。
  • 如果这是一个答案,我会把它放在答案部分。那是一条评论,我的意思是如果转到该链接并在最后三个文件中查找版本,您会找到相同的版本。所以看起来“本地”属性在当前版本中不再存在。
  • 请在您尝试使用local的位置发布。

标签: java xml eclipse spring


【解决方案1】:

Spring(和 Eclipse)将使用您在 schemaLocation 中声明的任何 xsd,而不管 jar 文件中的那个。这实际上是由 Spring 在它下面使用的 XML 解析器完成的验证。

如果您想使用reflocal 属性,您需要声明一个schemaLocation,它指向具有local 属性的架构。请注意,如果您这样做,生成的上下文将需要由 Spring jar 中存在的 BeanDefinitionParser 解析。

【讨论】:

    【解决方案2】:

    http://www.springframework.org/schema/beans/spring-beans.xsd 实际上指向 4.0 XSD,它没有 local。此外,eclipse 中存在与 spring 集成的错误,这可能是问题所在。 INT-1353

    此外,/was/ Eclipse 有一个配置选项来指定从 Classpath 加载 XSD,但我不能 100% 确定这是否有效,甚至不再存在。这里有一个截图:https://stackoverflow.com/a/2896051/1958771

    ~ sheenobu -> curl -s http://www.springframework.org/schema/beans/spring-beans.xsd | md5
    0483a5565138fe9f79c5fbe38c7c5969
    ~ sheenobu -> curl -s http://www.springframework.org/schema/beans/spring-beans-3.2.xsd | md5
    1562baeab9550e2149e9608dbb3bbadd
    ~ sheenobu -> curl -s http://www.springframework.org/schema/beans/spring-beans-4.0.xsd | md5
    0483a5565138fe9f79c5fbe38c7c5969
    

    【讨论】:

    • springframework.org/schema/beans/spring-beans.xsd的版本,明明是3.2版本。 "![CDATA[ Spring XML Beans Schema,版本 3.2 作者:Juergen Hoeller、Rob Harrop、Mark Fisher、Chris Beams 这定义了一种简单且一致的方法来创建由 Spring BeanFactory 管理、由 XmlBeanDefinitionReader 读取的 JavaBeans 对象命名空间。 ..]]"
    • 这是一个错字或标签错误,它不是 3.2 。更新了我的答案以证明这一点。
    【解决方案3】:

    您应该尝试改用&lt;ref bean="someBean"/&gt;

    【讨论】:

      【解决方案4】:

      我已经解决了在 xsi:schemaLocation 中使用旧的 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 的问题。 (因为我的项目也“旧”)

      【讨论】:

        【解决方案5】:

        如此处所述:http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/

        4.0 beans xsd 不再支持 ref 元素上的 local 属性,因为它确实支持不再提供常规 bean 引用的价值。升级到 4.0 架构时,只需将现有的 ref local 引用更改为 ref bean

        您可能知道 Spring 3.x 与 java 8 不完全兼容,因此您要么将不受支持且过时的 Java 7 与 Spring 3.x 一起使用,要么同时升级 Spring 和 JDK。我强烈推荐最新的

        【讨论】:

          猜你喜欢
          • 2016-07-24
          • 2020-01-01
          • 2013-08-16
          • 1970-01-01
          • 2013-05-04
          • 1970-01-01
          • 2018-02-11
          • 2014-02-21
          • 1970-01-01
          相关资源
          最近更新 更多