|
From: Juergen H. <ju...@in...> - 2005-03-16 18:54:46
|
Everybody, I've committed a significant revision of AbstractAutoProxyCreator and the associated TargetSourceCreator mechanism today. This has been planned since end of January, but had to wait till 1.2 because of non-backwards-compatible changes. The motivation for this is to allow lazy initialization of a singleton target through auto-proxying. We recently introduced LazyInitTargetSource for this, which doesn't create an actual target instance until first method invocation on the proxy. This goes beyond our standard "lazy-init" feature in the bean container, where fetching a reference already triggered target creation, even if the reference was just stored and not immediately used. LazyInitTargetSource worked nicely as-is, with individual ProxyFactoryBean definitions per target bean. The problem that remained was using it with auto-proxying: the auto-proxy machinery kicked in *after* creation of a bean instance, which is fundamentally too late for a TargetSourceCreator: we might want to pool objects there or lazily initialize a singleton target, so we don't need the default target creation - all we need is an early hook to expose our proxy. The old auto-proxy machinery always created a target bean instance on startup, even if the actually instances were held somewhere different, for example in a pool. This didn't hurt much, but it was unnecessary: one unused instance created there. For lazy initialization of a singleton target, this effect was a showstopper, though: the very point of lazy target initialization is that no instance gets created before actual access. What I've done to address this is: * added InstantiationAwareBeanPostProcessor extension of BeanPostProcessor interface, intercepting before instantiation * reworked AbstractAutoProxyCreator to check for custom TargetSourceCreator before instantiation of target bean * reworked TargetSourceCreator mechanism to work with bean class rather than bean instance (non-backwards-compatible) * reworked AbstractPrototypeBasedTargetSourceCreator into AbstractBeanFactoryBasedTargetSourceCreator * added LazyInitTargetSourceCreator, automatically creating a LazyInitTargetSource for each bean marked as "lazy-init" From the usage point of view, everything should be backwards-compatible, but not from the TargetSourceCreator implementation point of view (which shouldn't affect many people anyway). The goal was to allow for LazyInitTargetSourceCreator, which can be specified on (for example) a BeanNameAutoProxyCreator. It will automatically create LazyInitTargetSource for all bean definitions marked as "lazy-init". So activating this TargetSourceCreator will effectively lead to stronger "lazy-init" semantics: instead of simple lazy bean creation, it will expose a proxy first and not create the target until method invocation on that proxy. It's all already in CVS, so feel free to give it a try and share your thoughts on it :-) Juergen |