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...
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.
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