Announcement Announcement Module
No announcement yet.
how to make BeanFactory creating special bean, not getBean() Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to make BeanFactory creating special bean, not getBean()

    	<bean id="beanTest" class="com.louis.mock.TestBean"/>
        <bean id="bean1" class="com.louis.mock.TestBean1"/>
        <bean id="bean2" class="com.louis.mock.TestBean2"/>
        <bean id="bean3" class="com.louis.mock.TestBean3"/>
        <bean id="bean4" class="com.louis.mock.TestBean4"/>
    As we all know that BeanFactory would create the bean of beanTest when we call BeanFactory.getBean("beanTest"),

    Now, I want BeanFactory to create bean1 and bean2 after BeanFactory.getBean("beanTest"),

    In the mean time I must:
    1) I don't want to create bean3 and bean4, so we can't use preInstantiateSingletons()
    2) I don't want to call BeanFactory.getBean("bean1") and BeanFactory.getBean("bean2")

    How can I reach this?

    Thank in advance!


  • #2
    So if I understand correctly you want some dependencies between beans creation?
    If that's the fact then you take a look at the depends-on attribute for every bean. If that doesn't work the way you want then I guess you should find a way to intercept the bean creating; use InitializingBean on bean bean1 which can force the initializatio of bean1 and bean2 (pretty much like depends); look at BeanFactory or use some sort of interceptor...
    This problem looks like a generic one - didn't you find anything on the forums?


    • #3
      You may mistake my meaning

      depends-on attribute:
      the dependency is properly initialized before the dependent bean

      but I want to initialized the beans after the dependent bean, not "before" !

      I felt this problem is not like a generic one, before i posted this topic, I'd found on serval forums, but I get nothing ^-^

      Thank you for your advices.


      • #4
        If that doesn't work the way you want then I guess
        I thought this is what you want. See BeanFactory or use an interceptor - this way you can apply post-execution advice.


        • #5
          The way those beans are defined in the OP, they are all initialized when the context is loaded, no?


          • #6
            Yes, so i don't use context , but BeanFactory,