title: Inject dependency into static field
body: <p>I want to make template engine available in servlets. The concrete template engine implementation should be changeable behind the TemplateEngine interface. With usual dependency injection it could look like this:</p>
  
  <pre><code>public abstract class BaseServlet extends HttpServlet {
  
      private TemplateEngine templateEngine;
  
      public void setTemplateEngine(TemplateEngine te) {
        templateEngine = te;
      }
  
      protected void render(Result result, HttpServletResponse response) {
        templateEngine.render(result, resonse);
      }
  
  }
  </code></pre>
  
  <p>The disadvantage of this approach is that each Servlet that wants to use the render method has to extend BaseServlet. Therefore I'd like to have a statically imported render method.</p>
  
  <pre><code>public class TemplateEngineWrapper {
  
    @Inject
    static TemplateEngine templateEngine;
  
    public static void render(Result result, HttpServletResponse response) {
      templateEngine.render(result, resonse);
    }
  
  }
  </code></pre>
  
  <p>In the Servlet I would use it this way:</p>
  
  <pre><code>import static TemplateEngineWrapper.render;
  
  ...
  
  public void doGet(...) {
    render(new Result(200, "Everything is fine."), response);
  }
  
  ...
  </code></pre>
  
  <p>Is something wrong with this approach? If so: What would you suggest instead?</p>