13

I am currently going through Mkyong Spring 3.0 tutorial.

He goes on to clarify these 2 basic things.
1. Bean in different XML files

If you are referring to a bean in different XML file, you can reference it with a ‘ref‘ tag, ‘bean‘ attribute.

2. Bean in same XML file

If you are referring to a bean in same XML file, you can reference it with ‘ref‘ tag, ‘local‘ attribute.

The only thing I can make out is that the local attribute is not supported any more in version 4.1.5. For the timebeing, I have sticked to the

<ref bean="thebeaninstance"/>

and it works for both. <ref bean="..."> requires only it to be in the same context, or in a parent context.

But i am looking for something by which i will be able to resolve the difference once if somehow i encounter same ids in 2 different beans, and wish to refer to the one defined in different XML, since preference goes to the one defines in the same XML. Please suggest.

1

1 Answer 1

13

Spring dropped support for the local ref elements in version 4.0.1. This is from the notes:

Removed the ref 'local' attribute in spring-beans-4.0.xsd since 'local' lost its differentiating role to a regular bean ref back in the 3.1 days when we started allowing for the same bean id to reappear in a different beans section of the same configuration file (with a different profile). Issue: SPR-10437

See here: link

Basically, you should use the bean element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.