title: Spring, autowired jdbcTemplate is null when called from main method
body: <p>My application needs a static main method that is called from its JAR file on a server.  If main is static the methods it calls, as well as the fields must be static.  The problem is, my jdbcTemplate is autowired and is null when static (I understand this does not work).  Either I remove 'static' from my main and I cannot call it from the JAR, or I make everything in the class 'static' and the jdbcTemplate is null.  What is the best solution to this issue.</p>
  
  <p>Thanks in advance.</p>
  
  <p>*Note that main is not static in this example, when I run it on the server it says, 'main' must be static.  Please keep this in mind for any solution.</p>
  
  <pre><code>public class Purge {
  
   @Autowired
   protected JdbcTemplate jdbcTemplate;
  
   private int PURGE_DAYS = 14;
  
  /**
   * @param args
   */
  public void main(String[] args) {
      loadContext();
      purge();
  }
  
  ApplicationContext loadContext() {
      return new ClassPathXmlApplicationContext("applicationContext-purge.xml");
  }
  
  public void purge() {
      jdbcTemplate.execute("blah blah blah");
  }
  
  }
  </code></pre>