Unexpected error occurred in scheduled task
10:14 28 Mar 2017

I tried to run a scheduled task in my Spring-Boot application, using the default applicationConfig - I only added the annotation @EnableScheduling and configured the class with the method that is to be scheduled, per the following code sample:

@Component 
public class Task { 

 @Scheduled(cron ="*/10 * * * * *")
  public void init() {
    System.out.println("QuartzConfig initialized.");
    System.out.println(callService());
  }

  private String callService() {
    String urlService = "https://www.google.com";
    GetMethod method = new GetMethod(urlService );
    String response = "";
    try {
        client.executeMethod(method);
        response = method.getResponseBodyAsString();
    } catch (IOException e) {
       e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
    return response;
  }
}

However, when the task is called, the method callService returns the following error:

java.lang.NullPointerException: null

This, quite obviously, makes me sad.

java spring-boot scheduler