21

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

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

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.

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

"cvc-complex-type.3.2.2: Attribute 'local' is not allowed to appear in element '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

    <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" />
user3183400
  • 211
  • 1
  • 2
  • 6
  • Please show us the XML you are trying to validate with Eclipse. Edit your question. – Sotirios Delimanolis Jan 10 '14 at 20:59
  • if you go to http://www.springframework.org/schema/beans/ .. you will see the version doesnt even matter. – Ashish Jan 10 '14 at 21:02
  • @Ashish What do you mean version doesn't matter? That's not even my question. I'm saying two files, in this case, spring-beans.xsd and spring-beans-3.2.xsd say they are the same version but one defines the "local" attribute and the other doesn't. – user3183400 Jan 10 '14 at 21:06
  • if it was an answer I'd have put that in answer section. That was a comment and what I meant was if go to that link and look for the version in last three files , you 'd find the same version. So it looks like the attribute "local" no longer exists in current versions. – Ashish Jan 10 '14 at 21:10
  • Please post where you are trying to use `local`. – Sotirios Delimanolis Jan 10 '14 at 21:14

5 Answers5

38

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

tom
  • 1,647
  • 14
  • 15
16

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

The local attribute on the ref element 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 local references to ref bean when upgrading to the 4.0 schema.

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

Marat Asadurian
  • 593
  • 1
  • 6
  • 18
3

The http://www.springframework.org/schema/beans/spring-beans.xsd actually 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

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

~ 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
Community
  • 1
  • 1
Sheena Artrip
  • 1,990
  • 12
  • 16
  • Look at the version of http://www.springframework.org/schema/beans/spring-beans.xsd It clearly says version 3.2. "![CDATA[ Spring XML Beans Schema, version 3.2 Authors: Juergen Hoeller, Rob Harrop, Mark Fisher, Chris Beams This defines a simple and consistent way of creating a namespace of JavaBeans objects, managed by a Spring BeanFactory, read by XmlBeanDefinitionReader ... ]]" – user3183400 Jan 10 '14 at 22:12
  • It is a typo or mis-labeled, it's not 3.2 . Updated my answer to prove it. – Sheena Artrip Jan 12 '14 at 03:18
1

Spring (and Eclipse) will use whichever xsd you declared in the schemaLocation regardless of the one in the jar file. This is actually validation done by the XML parser that Spring uses underneath it all.

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

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
1

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

Jiri F.
  • 31
  • 2