Announcement Announcement Module
Collapse
No announcement yet.
Get Factory instead of Bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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

    Comment

    Working...
    X