Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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" />
like image 680
user3183400 Avatar asked Jan 10 '14 20:01

user3183400


3 Answers

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

like image 89
tom Avatar answered Sep 21 '22 16:09

tom


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

like image 45
Marat Asadurian Avatar answered Sep 18 '22 16:09

Marat Asadurian


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
like image 30
Sheena Artrip Avatar answered Sep 21 '22 16:09

Sheena Artrip