Results 1 to 3 of 3

Thread: BeanFactory init-method?

  1. #1
    Join Date
    Oct 2006
    Posts
    2

    Default BeanFactory init-method?

    I'm trying to implement a non-standard logger to be used by all beans created by the BeanFactory (don't ask why).

    I first overload the commons logging factory via a vm runtime flag, like

    -Dorg.apache.commons.logging.LogFactory= myLoggerFactory

    but I also would like to inject my own initialization method into the BeanFactory itself to handle myLoggerFactory configuration, something like what the BeanFactory does for normal beans via init-method.

    Is there any way to do this?

    There are other options of course (eg. myLogger can read properties files with a specific name in the classpath), but I would prefer not to impose the burden of additional config files on clients of this software.

    thx, jd

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Not sure what you want to do to be honest......

    Are you saying that the commons logging framework want to call "new myLoggerFactory()" and you want Spring to intercept that to provide dependency injection?

    You could maybe use Spring2 @Configurable, but that will only work so long as the applicationContext is created before myLogFactory.

    Alternatively you could define MyLogFactory as a normal spring BeanFactory and then use a BeanPostProcessor to inject into each bean (that exposed a setLogger for example)? More intrusive, but probably more reliable
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

  3. #3
    Join Date
    Apr 2006
    Posts
    110

    Default

    jaydee is ok, i think a good solution, you can also create your own custom extension in Spring 2 so a less (or none) instrusive between your logger and spring will happens.
    Si em veiessin caminar per sobre un llac, dirien que no sé nedar.
    http://alexsotob.blogspot.com

Posting Permissions

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