Announcement Announcement Module
Collapse
No announcement yet.
How does one inject a log object using commons.logging? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How does one inject a log object using commons.logging?

    I would like to use org.apache.commons.logging in a class and have that log object created and injected into the target object
    Code:
    import org.apache.commons.logging.Log
    class Foo {
      private Log log;
      public void setLog(Log inLog) {
        this.log = inLog;
      }
      ... other methods, etc.
    }
    
    spring config excerpt...
    <beans>
    
      <!-- use MethodInvokingFactoryBean to get a LogFactory?? -->
      <bean id="logFactory" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass"><value>org.apache.commons.logging.LogFactory</value></property>
        <property name="targetMethod"><value>getLog</value></property>
      </bean>
    
      <!-- use the LogFactory to get a Log object?? -->
    
      <bean id="logBean" class="org.apache.commons.logging.Log" factory-bean="logFactory">
        <property name="targetMethod"><value>getLog</value></property>
        <property name="arguments"><value>com.availity.db.edi.AvEdiFecsSelector(sp)</value></property>
      </bean>
    
      <!-- the bean that receives the log bean -->
    
      <bean id="beanWithLog" class="com.compucafe.BeanWithLog">
          <property name="log"><ref local="logBean"/>																       
      </bean>
    </beans>
    I want to set up this log using the spring app context. Is this possible and can anyone tell me what I need to change to get the above config to work.
    Last edited by hamiltonca; Jun 30th, 2006, 11:06 AM. Reason: Clairification; more details

  • #2
    Hi hamiltonca

    Try this class...

    http://static.springframework.org/sp...api/index.html

    Cheers
    Rick

    Comment


    • #3
      The URL is to the Javadoc index page. I would very much appreciate a pointer to the class you mentioned.

      Comment


      • #4
        Whoops! Where is the embarrassed smiley?

        http://www.springframework.org/docs/...ctoryBean.html

        Cheers
        Rick

        Comment

        Working...
        X