Announcement Announcement Module
Collapse
No announcement yet.
how to use IoC with crappy app servers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to use IoC with crappy app servers

    Spring problem

    We are using a home grown container that instantiates the first class and calls a method with a given
    signature. Therefore I can not use Spring IoC to instantiate this top level class that has many dependencies.

    Also this main class needs many other objects injected into it so I am now calling new Class1() etc
    (and those classes have upstream dependencies or objects that need to be created before these are created).

    What I would like to do is that within this class/method that gets instantiated by our server/container
    is to register it with the Spring Application Context (a reference) and then call springInit() which
    will then instantiate the rest of the upstream classes (and automatically call the setters in the already
    instantiated class to inject them).

    Is this possible?

    For example:

    Processor.java

    gets instantiated (empty constructor) and our craptaculous server automatically calls:
    public void init(params) throws Exception { ...
    springInit(); // here I want to write a method called springInit()
    }

    from here I would somehow call a method springInit() that would first register a reference to Processor.java
    and then instantiate other classes dependencies that Processor.java has
    and call setters within Processor.java (and create upstream dependencies that these classes that are injected has.

    hope that makes sense.

    Any help would be greatly appreciated.

  • #2
    It might be simpler to initialize the application context inside the init() method and subsequently delegate the rest of the startup to a bean taken from the context.
    Injecting dependencies is what Spring is for, after all...

    Comment


    • #3
      > might be simpler to initialize the application context inside the init() method > d subsequently delegate the rest of the startup to a bean taken from the > ntext.
      > jecting dependencies is what Spring is for, after all...

      so how is this actually done?

      If I init the context inside the init (instantiating all beans and dependencies, why do I need to delegate the rest of the startup to another bean taken from the context? and then how do I inject the objects created in the init into the same class that has the init() method? Do you understand what it is that I need to do? Can you provide an example?

      Comment


      • #4
        and exactly what does "delegate the rest of the startup" mean? do I create another application context? This is what it sounds like you are talking about.

        Comment

        Working...
        X