Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Oct 24, 2013 · 9 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

@spring-projects-issues
Copy link
Collaborator Author

Piotr Findeisen commented

Repro project spring-attic/spring-framework-issues#60

For me, it fails on Spring 3.1.2, 3.1.4.

@spring-projects-issues
Copy link
Collaborator Author

Piotr Findeisen commented

3.2.4 is affected too.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Indeed, this may happen if there are several beans of the same Class, with a property being overridden on one such bean but not the others.

I've changed the caching to a bean name key instead of a Class key. To be released in 4.0 RC1 as well as 3.2.5 next week.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Piotr Findeisen commented

Hi Juergen Hoeller,

Thanks for fixing this.
Will there be Spring version 3.1.5 released ever?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Piotr, there won't be any further 3.1.x releases. We consider the 3.2 line as a direct continuation of the 3.1 line, with as smooth an upgrade path as a a 3.1.5 release would be. So please upgrade to Spring Framework 3.2.5; if there any unexpected issues with the upgrade, let us know.

Note that Spring 3.2 has the same system requirements and full backwards compatibility with 3.1. Actually, 3.2 is the first generation of Spring with full runtime support for the 1.7 bytecode level; so if you're on Java 7, I would strongly recommend an upgrade to Spring 3.2 in any case.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 26, 2013

Piotr Findeisen commented

Hi,

Thanks for the explanation.

I've already once attempted upgrade from 3.1.2 to 3.1.4 (because of #15585), but I was defeated by #15623.

I will check on Monday whether #15623 still affects 3.2.4 (i.e. latest released 3.2).

Piotr

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 26, 2013

Juergen Hoeller commented

Piotr, as just mentioned in #15623, I'm about to fix that one through a backport to 3.2.5. So I hope there's nothing preventing you from an upgrade eventually.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Piotr Findeisen commented

(comment - 26/Oct/13) To be released in 4.0 RC1 as well as 3.2.5 next week.

Hi,

I see 3.2.5 delayed until today (JIRA says "Release Date: 06/Nov/13"). Is it indeed going to be released today or is it a 'moving target'?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Hi Piotr, this is indeed scheduled for release today (US time); so it should be available tomorrow morning (European time). You could test our latest 3.2.5 snapshot in the meantime, if you like :-)

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants