Skip to content

Commit 1bfa701

Browse files
committed
fixed MethodInvokingJobDetailFactoryBean for compatibility with Quartz 2.0/2.1 ()
1 parent 1d9d3e6 commit 1bfa701

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.scheduling.quartz;
1818

1919
import java.lang.reflect.InvocationTargetException;
20+
import java.lang.reflect.Method;
2021

2122
import org.apache.commons.logging.Log;
2223
import org.apache.commons.logging.LogFactory;
@@ -40,6 +41,7 @@
4041
import org.springframework.util.Assert;
4142
import org.springframework.util.ClassUtils;
4243
import org.springframework.util.MethodInvoker;
44+
import org.springframework.util.ReflectionUtils;
4345

4446
/**
4547
* {@link org.springframework.beans.factory.FactoryBean} that exposes a
@@ -80,13 +82,23 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
8082

8183
private static Class<?> jobDetailImplClass;
8284

85+
private static Method setResultMethod;
86+
8387
static {
8488
try {
8589
jobDetailImplClass = Class.forName("org.quartz.impl.JobDetailImpl");
8690
}
8791
catch (ClassNotFoundException ex) {
8892
jobDetailImplClass = null;
8993
}
94+
try {
95+
Class jobExecutionContextClass =
96+
QuartzJobBean.class.getClassLoader().loadClass("org.quartz.JobExecutionContext");
97+
setResultMethod = jobExecutionContextClass.getMethod("setResult");
98+
}
99+
catch (Exception ex) {
100+
throw new IllegalStateException("Incompatible Quartz API: " + ex);
101+
}
90102
}
91103

92104

@@ -296,7 +308,7 @@ public void setMethodInvoker(MethodInvoker methodInvoker) {
296308
@Override
297309
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
298310
try {
299-
context.setResult(this.methodInvoker.invoke());
311+
ReflectionUtils.invokeMethod(setResultMethod, context, this.methodInvoker.invoke());
300312
}
301313
catch (InvocationTargetException ex) {
302314
if (ex.getTargetException() instanceof JobExecutionException) {

0 commit comments

Comments
 (0)