Skip to content
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

AutowireUtils requires ObjectFactory to be Serializable [SPR-7264] #11923

Closed
spring-projects-issues opened this issue Jun 7, 2010 · 2 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

Kenny MacLeod opened SPR-7264 and commented

Since Spring 3.0, AutowireUtils.resolveAutowiringValue() has required that all ObjectFactory-implementing classes also implement Serializable. This means that when passing an ObjectFactory to ConfigurableListableBeanFactory.registerResolvableDependency(), this must be Serializable.

This was not the case in 2.5.6, however, and so code written to use this facility will not work in 3.0.x unless Serializable is introduced. This is invasive to the client code, and in many cases is highly inappropriate.

I'm not sure why this check is being made. AutowireUtils is constructing a ObjectFactoryDelegatingInvocationHandler which also implements Serializable, but there doesn't seem to be a reason for this.

Can this check be removed?


Affects: 3.0 GA, 3.0.1, 3.0.2

Referenced from: commits cc23820

@spring-projects-issues
Copy link
Collaborator Author

Kenny MacLeod commented

In addition, in cases where Objectfactory is used, AutowireUtils requires that the requiredType is an interface. If it is not, it silently fails.

This effectively adds two very right constraints on the resolvable dependencies, constraints not specified in the javadoc for ConfigurableListableBeanFactory.registerResolvableDependency(), and which were not present at all prior to 3.0.x. At the very least, the javadoc should be changed to reflect the constraints, but it would be much preferable to refactor the code to not require them at all.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Good catch! We do want special handling of serializable factory objects there but forgot to handle the non-serializable factory case properly: We simply need to call objectFactory.getObject() directly in that case.

Fixed for 3.0.3. Will be available in tonight's 3.0.3 snapshot - feel free to give it an early try...

Juergen

@spring-projects-issues spring-projects-issues added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0.3 milestone Jan 11, 2019
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