Java spring-beans.xsd没有定义;“本地”;。为什么?
几乎每个spring项目都使用spring-beans.xsd(更准确地说是引用它)。但是,如果查看该文件,您将看到它是3.2版,并且没有“local”属性的定义 更有趣的是,这确实定义了“本地” 此外,由于spring.schema的缘故,文件从jar(org/springframework/beans/factory/xml/spring-beans-3.2.xsd)中被拉出,因此我认为任何项目都不会有编译或运行时问题 另一方面,我认为Eclipse的xml验证器只使用internet链接,并显示一个xml错误,更具体地说: “cvc复杂类型。3.2.2:属性'local'不允许出现在元素'ref'中” 这是虫子吗 编辑: 根据要求,这是我的spring标题:Java spring-beans.xsd没有定义;“本地”;。为什么?,java,xml,eclipse,spring,Java,Xml,Eclipse,Spring,几乎每个spring项目都使用spring-beans.xsd(更准确地说是引用它)。但是,如果查看该文件,您将看到它是3.2版,并且没有“local”属性的定义 更有趣的是,这确实定义了“本地” 此外,由于spring.schema的缘故,文件从jar(org/springframework/beans/factory/xml/spring-beans-3.2.xsd)中被拉出,因此我认为任何项目都不会有编译或运行时问题 另一方面,我认为Eclipse的xml验证器只使用internet链接,
<?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" />
Spring(和Eclipse)将使用您在schemaLocation
中声明的xsd
,而不考虑jar
文件中的xsd。这实际上是由Spring在其下面使用的XML解析器进行的验证
如果要使用ref
的local
属性,则需要声明一个指向具有local
属性的架构的schemaLocation
。请注意,如果执行此操作,生成的上下文将需要由Springjar
中存在的BeanDefinitionParser
进行解析,该解析器实际上指向4.0 XSD,而该XSD没有本地文件。此外,eclipse和spring集成中存在可能是问题所在的bug
此外,eclipse还有一个/was/configuration选项来指定从类路径加载xsd,但我不能100%确定这是否有效,甚至不再存在。这里有一个截图:
您应该尝试使用
我已经解决了在xsi:schemaLocation中使用older的问题。(因为我的项目也“老了”)如下所述:
ref元素上的local属性在4.0bean xsd中不再受支持,因为它不再提供常规bean引用的值。升级到4.0模式时,只需将现有的ref-local引用更改为ref-bean
正如您可能知道的,Spring3.x与Java8不完全兼容,因此您要么将不受支持且过时的Java7与Spring3.x一起使用,要么同时升级Spring和JDK。我强烈推荐最新的,请向我们展示您试图用Eclipse验证的XML。编辑您的问题。如果您转到。。你会看到版本根本不重要。@Ashish你说版本不重要是什么意思?这甚至不是我的问题。我说的是两个文件,在本例中,spring-beans.xsd和spring-beans-3.2.xsd说它们是相同的版本,但一个定义了“local”属性,另一个没有。如果这是一个答案,我会把它放在答案部分。这是一个评论,我的意思是,如果你去那个链接,在最后三个文件中查找版本,你会发现相同的版本。因此,属性“local”在当前版本中似乎不再存在。请在尝试使用
local
的地方发布。请查看它的版本,清楚地显示版本3.2。“![CDATA[SpringXMLBeans模式,版本3.2作者:Juergen Hoeller,Rob Harrop,Mark Fisher,Chris Beams这定义了一种创建JavaBeans对象名称空间的简单而一致的方法,由Spring Bean工厂管理,由XmlBeanDefinitionReader读取…]”这是一种打字错误或标签错误,而不是3.2。更新了我的答案来证明这一点。
~ 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