spring-beans.xsd没有定义"local".为什么?

use*_*400 19 java xml eclipse spring

几乎每个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验证器仅使用互联网链接并显示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">
Run Code Online (Sandbox Code Playgroud)

编辑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" />
Run Code Online (Sandbox Code Playgroud)

tom*_*tom 35

你应该尝试使用<ref bean="someBean"/>.


Mar*_*ian 15

作为这里所说:http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/

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

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


Sot*_*lis 1

Spring(和 Eclipse)将使用xsd您在 中声明的任何一个schemaLocation,无论文件中的是什么jar。这实际上是由 Spring 在其底层使用的 XML 解析器完成的验证。

如果要使用local的属性ref,则需要声明schemaLocation指向具有该属性的模式local。请注意,如果您这样做,生成的上下文将需要可由BeanDefinitionParserSpring 中存在的上下文进行解析jar