Attribute 'local' is not allowed to appear in element 'ref' in Spring 4.1.5

拈花ヽ惹草 提交于 2021-01-26 11:20:09

问题


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:


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.



来源:https://stackoverflow.com/questions/29049183/attribute-local-is-not-allowed-to-appear-in-element-ref-in-spring-4-1-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!