On Fri, Jan 13, 2012 at 12:14 PM, Douglas Hubler <[email protected]> wrote:

> Someone discovered using lookup functions was a way to avoid circular
> references
>
> <bean a>
>  <bean b>
> </bean>
>
> <bean b>
>  <lookup bean a>
> </bean>
>
> The problem with this is that bean b needs to be abstract so spring
> can inject the method.  Abstract classes do not warn you when a class
> has not implemented a particular interface fully which is an
> incredibly valuable thing to know, especially in refactoring projects
> as I discovered.
>
> In every case I analyzed the circular dependency and easily avoid the
> issue by shuffling code around.  In each case, the final
> implementation was more cohesive, and overall more clear.
>
> Another use of lookup functions is to instantiate prototype beans (as
> opposed to singleton beans). I admit this *is* a legitimate use of
> this spring feature however I found that the issue with abstract
> classes I mentioned earlier to be so great it's not worth using lookup
> functions IMO.  Instead, simply keeping a reference to the bean
> factory and calling beanFactory.getBean to be fairly simple workaround
> however primitive it is.
>
I think that another good way is to make one of the beans to implement
ApplicationContextAware interface and then to look up for the bean you want
using ApplicationContext.getBean. I recall that are many examples  across
the project that make use of this Spring technique

Mircea
-----------------------------------------------------
Come and see us at sipXecs CoLab at CSU March 5 and 6 2012

>
> Please respond if you disagree or have comments, otherwise I'll assume
> we're all ok w/avoiding this feature.
>
> --
> Join me to talk about sipXecs and the upcoming version 4.6 at
>   CoLab @ CSU  March (5th & 6th).
>      http://www.sipfoundry.org/sipx-colab
> Hack with me on at the CoLab Hackfest.
>   http://wiki.sipfoundry.org/display/sipXecs/2012+sipX-CoLab+Hackfest
> _______________________________________________
> sipx-dev mailing list
> [email protected]
> List Archive: http://list.sipfoundry.org/archive/sipx-dev/
>
_______________________________________________
sipx-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev/

Reply via email to