title: Spring - injecting Log4j logger without explicit specification
body: <p>I'm using Spring XML-based DI to create my classes.</p>
  
  <p>Also I'm using log4j and I'm injecting <code>org.apache.log4j.Logger</code> as a constructor argument in each class which needs it.</p>
  
  <p>So I have a lot of entries in Spring config like following:</p>
  
  <pre><code>&lt;bean id="myClass" class="com.myProject.MyClass"&gt;
      ...
      &lt;constructor-arg type="org.apache.log4j.Logger"&gt;
          &lt;bean class="org.apache.log4j.Logger" factory-method="getLogger"&gt;
              &lt;constructor-arg value="com.myProject.MyClass"/&gt;
          &lt;/bean&gt;
      &lt;/constructor-arg&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Class code:</p>
  
  <pre><code>package com.myProject;
  
  import org.apache.log4j.Logger;
  
  public class MyClass {
      private final Logger logger;
  
      public MyClass (
              ...
              Logger logger) {
          ...
          this.logger = logger;
      }
  
      ...
  }
  </code></pre>
  
  <p>Although it works perfectly, I wonder if there is any possibility to default <code>constructor-arg</code> of the logger to the class name, whose constructor the created logger should be passed to?</p>
  
  <p>E.g. like this <a href="https://stackoverflow.com/a/35262698/2858407">solution</a> for Unity DI and log4net which are somewhat analogs in .Net.</p>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>I see two reasons of injecting <code>Logger</code> rather than initializing it inside the class.</p>
  
  <p>First of all, statements like <code>private final Logger logger = LogManager.getLogger(MyClass.class);</code> are usually copy-pasted, so they are prone to mistake in the logger name.</p>
  
  <p>Moverover, I'd like to cover error logging with unit tests, e.g. pass a mock of <code>Logger</code> into the constructor and than verify that after some erroneous action <code>logger.Error</code> has been called.</p>