Results 1 to 2 of 2

Thread: Get Factory instead of Bean

  1. #1
    Join Date
    Apr 2006
    Location
    Saint-Petersburg, Russia
    Posts
    50

    Question Get Factory instead of Bean

    Hello!
    Another stupid question:

    I have beans like:
    Code:
    <bean id="beanA" class="ClassB">
      <property name="prop1" ref="beanB"/>
    </bean>
    
    <bean id="beanB" class="BeanBFactory">
    </bean>
    For so, beanA expects classA in getProp1
    For beanB I have singleton BeanFactory (BeanBFactory) used for making beanB

    So, by default beanB created then application is initialized and tried to set beanB to beanA.

    But I need to create beanB only then it is really started to be used in beanA - not during application start, but during user working...

    In this case I should set into beanA not beanB - but it's factory - to create object via it then it is required.

    OK, I changed ClassA::setProp1 so, it expects BeanBFactory - but still beanB is created during application initialization

    And only if I remove
    Code:
    implements BeanFactory
    from my BeanBFactory everything started to work.

    So, is it correct solution, or there are some standard pattern exists in Spring for such cases?

    Thank you for any advice
    With best regards,
    Alexey Kakunin
    EmForge: Liferay based project hosting service

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Using a BeanFactory like that is discouraged as you needlessly tie your implementation to Spring.
    You can solve your problem by using a org.springframework.aop.target.LazyInitTargetSourc e. Have a look at the API documentation of that class for an example about its usage.

    Regards,
    Andreas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •