Announcement Announcement Module
Collapse
No announcement yet.
Bean creation notification. or post-processing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean creation notification. or post-processing

    Edit -- never mind, my use case works after implementing my example below -- my problem is not what I thought it was

    ******

    I have just built the prototype for a system that has multiple modules, each spring-loaded. How and which modules are determined by spring configuration, so I'm combining multiple contexts. There are several beans that depend on other beans, so I have to be careful in my constructors not to attempt a reference to another bean until it has been completely initialized. I'll try to lay out an example:

    class A {
    private B b_ref;

    A() {
    b_ref = springContext.getBean("B", B.class);
    }
    }

    class B {
    private C c_ref;

    B() {
    c_ref = springContext.getBean("C", C.class);
    }
    }

    class C {
    C() {
    }
    }

    My spring config could look like this:

    <bean id="A" class="A" depends-on="B"/>
    <bean id="B" class="B" depends-on="C"/>
    <bean id="C" class="C"/>

    I *think* what is going to happen here is that when the constructor of B is called, I'm going to get an error because the spring configuration is still loading. If I understand, the depends-on attribute will delay the construction of A and B and walk backwards after C is built.

    I'm going to build a simple test case to see if this is true, but it seems to be what I am finding in the project I am working on. So my solution would then be to add an init method to A and B, where I would then do what I'm doing in their constructors now, but I think that is still producing the same error situation.

    If all this is true so far, then I really can't have spring call upon and spring-loaded bean until after configuration parsing has completed altogether. I could of course uses spring to provide those references to my beans, but I don't want to do that because I have a master container bean that serves these references on an as-needed basis.

    So how should this be handled? I see that there is an event system. Is there a spring-way to handle post-processing of beans after the construction phase is complete? Maybe I've misunderstood how this works?

    Thanks for any help you can provide.

    Scott
    Last edited by jackett_dad; Jan 12th, 2012, 03:56 PM.
Working...
X