title: Can't use @Autowired JPA Repository in Main method of Spring Boot application
body: <p>I've autowired a JPA repository that adds dummy data in my H2 database before the application starts.
  But is there a reason as to why I can't use it in the main () method but am able to use it in the runner() method?</p>
  <pre><code>@SpringBootApplication
  public class FullstackApplication {
      
      @Autowired
      private CarRepository carRepository;
      
      private static final Logger logger = LoggerFactory.getLogger(FullstackApplication.class); 
  
      public static void main(String[] args) {
          carRepository. // Here I get a compilation error: Cannot make a static reference to a non-static field
          SpringApplication.run(FullstackApplication.class, args);
  
      }
      
      @Bean
      CommandLineRunner runner(){
          return args -&gt; {
              // Save demo data to database
              carRepository.save(new Car(&quot;Ford&quot;, &quot;Mustang&quot;, &quot;Red&quot;,
              &quot;ADF-1121&quot;, 2017, 59000));
              carRepository.save(new Car(&quot;Nissan&quot;, &quot;Leaf&quot;, &quot;White&quot;,
              &quot;SSJ-3002&quot;, 2014, 29000));
              carRepository.save(new Car(&quot;Toyota&quot;, &quot;Prius&quot;, &quot;Silver&quot;,
              &quot;KKO-0212&quot;, 2018, 39000));
          };
      }
  }
  </code></pre>