Issue Details (XML | Word | Printable)

Key: SPR-3608
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Andy Piper
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Framework

Need a way of pre-instantiating FactoryBean singleton instances

Created: 22/Jun/07 06:22 AM   Updated: 02/Jul/07 04:42 PM
Component/s: SpringCORE
Affects Version/s: 2.0.6
Fix Version/s: 2.1 M3, 2.0.7

Time Tracking:
Not Specified


 Description  « Hide
Given a network of FactoryBeans, all of the dependent beans will be instantiated by preInstantiateSingletons() except for the root level of the tree. Calling getObject() in afterPropertiesSet() does not solve this because the BeanPostProcessors do not get run. Instead we need a way of marking a Factory as being "eagerly" initialized by preInstantiateSingletons.

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Juergen Hoeller added a comment - 02/Jul/07 02:54 PM
Andy, I've added an "isEagerInit()" method to the existing SmartFactoryBean interface, making "preInstantiateSingletons()" trigger a full getBean call and hence making post-processors apply to an exposed object eagerly.

This should be available in tonight's 2.1 M3 and 2.0.7 snapshots. Please give it a try...

Juergen

Paul Benedict added a comment - 02/Jul/07 04:31 PM
I hope you don't mind me nitpicking at the name :-) There seems to be some shuffling between "instantiation" and "initialization" here. Do you intend that? Would isEagerInstantiate be more inline with preInstantiateSingletons? Or just an isEager (ala isPrototype and isSingleton)?

Juergen Hoeller added a comment - 02/Jul/07 04:42 PM
You do have a point there :-)

However, in terms of a FactoryBean, this does actually refer to initialization, since the FactoryBean fully initializes the object that it exposes - or, from a different perspective, asks the container to eagerly initialize the exposed object through obtaining it on startup. This is pretty similar to the notion of 'lazy init' for a standard bean definition - using the 'init' terminology there as well.

Arguably, it's "preInstantiateSingletons" which should rather be named "preInitializeSingletons" or "preObtainSingletons" - or whatever. But that method is quite a historic artifact ;-) hence we're probably going to leave the name as-is, since it does instantiate the singletons as part of the process.

Juergen