Skip to content

Duplicate bean id allowed in same XML file by using name attribute [SPR-2285] #6974

Closed
@spring-projects-issues

Description

@spring-projects-issues

Colin Sampaleanu opened SPR-2285 and commented

The bean factory and application context contract clearly states (as per our docs) that within one definition xml file a bean id must be unique.

This is enforced by the XML parser when using the "id" attribute exclusively because this is flagged as an XML IDREF attribute. However, by combining the use of the id attribute and the name attribute, or just using the name attribute exclusively, it is possible to have 2 or more bean definitions in the same xml file with the same id. This is silently accepted with the last bean definition winning out.

The bean definition reader must basically track ids, however they are supplied, and enforce the same semantics from usage of the "name" attribute as from usage of the "id" attribute.

A related question is what should happen in the case of <import>? An argument could be made either way here.


Affects: 2.0 RC2

Attachments:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions