spring-beans.xsd没有定义“local”。为什么?

2022-09-02 02:28:06

几乎每个春季项目都使用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验证器,我认为,它只使用互联网链接,并显示一个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" />

答案 1

您应该尝试改用。<ref bean="someBean"/>


答案 2

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

ref 元素上的 local 属性在 4.0 beans xsd 中不再受支持,因为它不再提供常规 Bean 引用的值。只需在升级到 4.0 架构时将现有的 ref 本地引用更改为 ref Bean 即可。

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


推荐