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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21054171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:13:24  来源:igfitidea点击:

spring-beans.xsd does not define "local". Why?

javaxmleclipsespring

提问by user3183400

Almost every spring project uses spring-beans.xsd (refers to it to be more precise). However, if you look at the file, http://www.springframework.org/schema/beans/spring-beans.xsd, you'll see that it is version 3.2 and doesn't have a definition for the attribute "local".

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

What's even more interesting, is that http://www.springframework.org/schema/beans/spring-beans-3.2.xsddoes actually define "local".

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

Also since the file is pulled out of the jar (org/springframework/beans/factory/xml/spring-beans-3.2.xsd) due to spring.schema, I don't think any project will have compile or runtime issues.

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

Eclipse's xml validator on the other hand, I think, uses only the internet link and shows an xml error, more specifically :

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

"cvc-complex-type.3.2.2: Attribute 'local' is not allowed to appear in element 'ref'"

“cvc-complex-type.3.2.2:属性‘local’不允许出现在元素‘ref’中”

Is this is a bug?

这是一个错误吗?

Edit: As per request, this is my spring header:

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

<?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">

Edit 2: here is where I'm using local

编辑 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" />

回答by Sotirios Delimanolis

Spring (and Eclipse) will use whichever xsdyou declared in the schemaLocationregardless of the one in the jarfile. This is actually validation done by the XML parser that Spring uses underneath it all.

Spring(和 Eclipse)将使用xsdschemaLocationjar文件中声明的任何一个。这实际上是由 Spring 在其底层使用的 XML 解析器完成的验证。

If you want to use the localattribute of ref, you will need to declare a schemaLocationthat points to a schema that has the localattribute. Note that if you do do this, the generated context will need to be parseable by the BeanDefinitionParserthat exists in your Spring jar.

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

回答by Sheena Artrip

The http://www.springframework.org/schema/beans/spring-beans.xsdactually points to the 4.0 XSD, which does NOT have local. Additionally, There are bugs in eclipse with spring integration that could be the issue. INT-1353

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

Additionally, there /was/ a configuration option for eclipse to specify loading XSDs from Classpath, but I'm not 100% sure this works or even exists anymore. There is a screenshot of that here: https://stackoverflow.com/a/2896051/1958771

此外,还有 /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

回答by tom

You should try to use <ref bean="someBean"/>instead.

你应该尝试使用<ref bean="someBean"/>代替。

回答by Jiri F.

I have solved the problem with using older http://www.springframework.org/schema/beans/spring-beans-3.2.xsdin xsi:schemaLocation. (As my project is "older" as well)

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

回答by Marat Asadurian

As stated here: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/

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

The localattribute on the refelement is no longer supported in the 4.0 beans xsd since it does not provide value over a regular bean reference anymore. Simply change your existing ref localreferences to ref beanwhen upgrading to the 4.0 schema.

本地的上属性裁判不再支持元素在4.0豆XSD,因为它没有提供比普通豆的参考价值了。升级到 4.0 模式时,只需将现有的ref 本地引用更改为ref bean

As you might know Spring 3.x is not fully compatible with java 8, so you either use unsupported and outdated Java 7 with Spring 3.x, or upgrade both Spring and JDK. I would strongly recommend the latest

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