Unexpected error occurred in scheduled task

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 = ""; 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.

2

1 Answer

thanks for the comments I solved this added next code to init method

 public Task(){ client = new HttpClient(); client.getParams().setParameter("http.useragent", "Bacon/1.0"); } 

thanks to @edgarNgwenya

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like