title: NullPointerException in spring boot main method
body: <p>I want to set a session value when running the main application. I tried the following way:</p>
  
  <pre><code>@SpringBootApplication
  public class WebApplication extends SpringBootServletInitializer {
  
  @Autowired
  public HttpServletRequest request;
  
  @Autowired
  private CountryService countryService;
  
  private static Class&lt;WebApplication&gt; applicationClass = WebApplication.class;
  
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(applicationClass);
  }
  
  public void set_session_country(){
      request.getSession().setAttribute("session_countries", countryService.getAllCountry());
  }
  
  public static void main(String[] args) {
      WebApplication webApplication = new WebApplication();
      webApplication.set_session_country();
      SpringApplication.run(WebApplication.class, args);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>when running application, occurred NullPointerException</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NullPointerException
        at com.paid.webapp.WebApplication.set_session_country
        at com.paid.webapp.WebApplication.main</p>
  </blockquote>