Paste data after job completion into Quartz Scheduler using spring

I am working on a task in which I need to save the status of a job in a database, but when I tried to do it, he gave it to me java.lang.nullpointerexception. I think this is because whenever I tried to select / save / update any record from the database only then it gives me an error like this.

Here is my code

public class PostFBJob implements Job {

    private SchedulerService schedulerService;

    private SubCampaignService subCampaignService;

    @SuppressWarnings("unchecked")
    public void execute(JobExecutionContext context) throws JobExecutionException {

        JobDetail jobDetail = context.getJobDetail();
        JobDataMap jobDataMap = jobDetail.getJobDataMap();

        schedulerService = (SchedulerService) jobDataMap.get("schedulerService");

        SubCampaign subCampaign = (SubCampaign) jobDataMap.get("subCampaign");

        if (prStreamItem.getName().equalsIgnoreCase("Facebook") && StringUtils.isNotBlank(branch.getFbAccessToken())) {
            FacebookService facebookService = FacebookService.getSingleton();
            try {
                subCampaign.setStatus("Completed");
                subCampaign.setMessage("Completed");

                subCampaignService.updateSubCampaign(subCampaign);

            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
}

Exception

java.lang.NullPointerException
    at com.ace.Job.SubCampaignJob.execute(SubCampaignJob.java:147)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Error: java.lang.NullPointerException

Please help me solve this problem. I am new to Spring and Quartz.

Thank you in advance

+4
source share
2 answers

I think the answer you are looking for is here

Please check below link

Hibernate

+3

- subCampaignService. , spring.

, .

  • @ComponentScan({"com.ace"})

  • XML

    <context:component-scan base-package="com.ace"/>

null , :

try {
    subCampaign.setStatus("Completed");
    subCampaign.setMessage("Completed");
    if(subCampaign != null && subCampaignService != null) //Check is not null to subCampaign before update
    subCampaignService.updateSubCampaign(subCampaign);
} catch (Exception e) {
     log.error("", e);
}
+4

Source: https://habr.com/ru/post/1617217/


All Articles