[英]Is it possible to generate java source files from a spring-beans.xsd which is generated from the spring-beans.dtd?
[英]spring-beans.xsd does not define “local”. Why?
几乎每个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">
编辑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" />
您应该尝试使用<ref bean="someBean"/>
。
如上所述: 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。 我强烈推荐最新的
http://www.springframework.org/schema/beans/spring-beans.xsd实际指向4.0 XSD,它没有本地 。 另外,在Eclipse中存在可能是问题的弹簧集成中的错误。 INT-1353
另外,有一个/一个配置选项让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
Spring(和Eclipse)将使用您在schemaLocation
声明的任何xsd
,而不管jar
文件中的那个。 这实际上是由Spring使用的XML解析器完成的验证。
如果要使用ref
的local
属性,则需要声明一个指向具有local
属性的模式的schemaLocation
。 请注意,如果您这样做,生成的上下文将需要由Spring jar
中存在的BeanDefinitionParser
进行解析。
我在xsi:schemaLocation中使用旧的http://www.springframework.org/schema/beans/spring-beans-3.2.xsd解决了这个问题。 (因为我的项目也“老了”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.