diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java index dd71eef9a1b..49563f85a8f 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java +++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.scheduling.quartz; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,6 +41,7 @@ import org.springframework.beans.support.ArgumentConvertingMethodInvoker; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MethodInvoker; +import org.springframework.util.ReflectionUtils; /** * {@link org.springframework.beans.factory.FactoryBean} that exposes a @@ -80,6 +82,8 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod private static Class jobDetailImplClass; + private static Method setResultMethod; + static { try { jobDetailImplClass = Class.forName("org.quartz.impl.JobDetailImpl"); @@ -87,6 +91,14 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod catch (ClassNotFoundException ex) { jobDetailImplClass = null; } + try { + Class jobExecutionContextClass = + QuartzJobBean.class.getClassLoader().loadClass("org.quartz.JobExecutionContext"); + setResultMethod = jobExecutionContextClass.getMethod("setResult"); + } + catch (Exception ex) { + throw new IllegalStateException("Incompatible Quartz API: " + ex); + } } @@ -296,7 +308,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { try { - context.setResult(this.methodInvoker.invoke()); + ReflectionUtils.invokeMethod(setResultMethod, context, this.methodInvoker.invoke()); } catch (InvocationTargetException ex) { if (ex.getTargetException() instanceof JobExecutionException) {