title: What is the right way to use an injected bean in a static method?
body: <p>This question might seem a little odd. Suppose I have a Service which I want to use in a Utility class that has some static methods. The Service is a Spring bean, so naturally I will for example use a setter and (@Autowired) to inject it into my utility class.
  As it is mentioned in Spring's documentation, all beans are static in the bean context. So when you want to inject a bean in a class you don't have to use "static" modifier. See below:</p>
  
  <pre>
  <code>
  public class JustAClass{
    private Service service;
  
    public void aMethod(){
       service.doSomething(....);
    }
  
    @Autowired
    public void setService(Service service){
       this.service = service;
    }
  
  }
  </code>
  </pre>
  
  <p>Now going back to what I mentioned first (Using Service in a static Method):</p>
  
  <pre>
  <code>
  public class JustAClass{
    private static Service service;
  
    public static void aMethod(){
       service.doSomething(....);
    }
  
    @Autowired
    public void setService(Service service){
       this.service = service;
    }
  
  }
  </code>
  </pre>
  
  <p>Although Service is static, I am forced to put static behind its definition. This is a bit counter-intuitive to me. is this wrong? or is it a better way?
  Thanks</p>