How to add Quartz JobListener

Tags: , , , ,

I am writing a java/spring library to include in other projects that are using quartz. I need it to log something before each task is executed.

I have a simple JobListener that looks like this:

public class MyJobListener extends JobListenerSupport {
    private static final Logger log = LogManager.getLogger(LoggingJobListener.class);

    public String getName() {
        return "MyJobListener";

    public void jobToBeExecuted(JobExecutionContext context) {"job will start")   

I know we can do something like this to add joblisteners:

scheduler.getListenerManager().addJobListener(myJobListener, allJobs());

But how can I get the scheduler to add so I can add the listener?

I have tried implementing the SchedulerFactoryBeanCustomizer but can’t figure out how to add the listener (since the scheduler is not created yet?)


You can add a Postconstruct and add JobListener there.

public class JobListenerConfig {

    private SchedulerFactoryBean schedulerFactoryBean;

    public void addListeners() throws SchedulerException {

                            .addJobListener(new MyJobListener());

Source: stackoverflow