Skip to content

@Autowired setter randomly called twice or not called at all when two beans of the same class [SPR-11027] #15655

@spring-projects-issues

Description

@spring-projects-issues

Piotr Findeisen opened SPR-11027 and commented

According to docs, @Autowired setter should not be called when an explicit value is set in XML context configuration.

Unfortunately, the AutowiredAnnotationBeanPostProcessor.injectionMetadataCache cache is per Class, but it's contents, especially AutowiredMethodElement.skip attribute (inherited by AutowiredMethodElement from superclass) is specific bean definition dependent.

As a result, if I have two unrelated beans of the same class, they 'share' their autowiring behavior.

  • an unlucky bean using @Autowired may have its setter not called at all
  • an unlucky bean providing explicit value for @Autowired setter may have its setter called twice
  • depending on the order in which beans are initialized.

Affects: 3.1.2, 3.1.4, 3.2.4

Referenced from: commits ce001c2, 4675bc4, 393cfcf

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