Announcement Announcement Module
Collapse
No announcement yet.
how to put an object into spring context as a spring bean ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to put an object into spring context as a spring bean ?

    Hello,

    I'd like to put an object (the currently running ant task) into a spring context so that it can be injected into beans (to use ant console logging).

    I've setup a StaticApplicationContext and use it as parent context to load my beans from an XML context-definition, so that it can be used as a dependency from beans definitions.

    How can I register my object in the static context ?

  • #2
    Re: how to put an object into spring context as a spring bea

    Originally posted by ndeloof
    Hello,

    I'd like to put an object (the currently running ant task) into a spring context so that it can be injected into beans (to use ant console logging).
    Do you run a single task? Or will multiple tasks run in the scope of a single applicationcontext?

    And I think you should tell more about your requirements/problem because they are a littlebit unusual.

    Comment


    • #3
      I've found the solution :
      Code:
      StaticApplicationContext ctx = new StaticApplicationContext();
      ctx.getDefaultListableBeanFactory().registerSingleton("log", this);
      Just for info, my tool uses commons-logging and is Spring based for IoC. I'm writting an ANT task to run it (in fact, a maven plugin)

      commons-logging doesn't redirect logs to ANT console, so I've made my ant task implement Log interface and put it into spring context. I've added to my beans a 'setLog(Log)' method, so I can replace the logger commons-logging has set.

      Using this, my beans get the "Ant console redirect" Log and I get my debugs on console.

      Comment

      Working...
      X