Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jan 2005
    Posts
    144

    Default 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. #2
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default Re: how to put an object into spring context as a spring bea

    Quote 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.

  3. #3
    Join Date
    Jan 2005
    Posts
    144

    Default

    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.

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •