On Fri, Jan 13, 2012 at 7:53 AM, Mircea Carasel <[email protected]> wrote:
>
>
> 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

I think it's BeanFactoryAware.  If so, yes, we're talking about the
same thing.  ApplicationContextAware is for catching spring events.
_______________________________________________
sipx-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipx-dev/

Reply via email to