<bean id="bspReceiptNormalPushTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="bspReceiptNormalPushJob" />
<property name="cronExpression" value="0 0/1 * * * ?" /><!-- 每隔1分钟触发一次 -->
</bean>
<bean id="bspReceiptNormalPushJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.MyDetailQuartzJobBean" />
<property name="jobDataAsMap">
<map>
<!-- 要反射的service -->
<entry key="targetObject" value="bspReceiptCallService" />
<!-- 要反射的service 中要执行的方法 -->
<entry key="targetMethod" value="batchBspReceiptNormalPush" />
<!-- 是否允许任务并发执行。当值为false时,表示必须等到前一个线程处理完毕后才再启一个新的线程 -->
<entry key="concurrent" value="false" />
</map>
</property>
</bean>
MyDetailQuartzJobBean.java
import java.lang.reflect.Method;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;
import com.sfiec.oms.common.SpringUtil;
public class MyDetailQuartzJobBean extends QuartzJobBean {
private static final Logger LOGGER = LoggerFactory.getLogger(MyDetailQuartzJobBean.class);
private String targetObject;
private String targetMethod;
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
try {
LOGGER.debug("execute [" + targetObject + "] at once >>>>>>");
Object otargetObject = SpringUtil.getBean(targetObject);
Method m = null;
try {
m = otargetObject.getClass().getMethod(targetMethod);
m.invoke(otargetObject);
} catch (SecurityException e) {
LOGGER.error(e.getMessage());
} catch (NoSuchMethodException e) {
LOGGER.error(e.getMessage());
}
} catch (Exception e) {
throw new JobExecutionException(e);
}
}
public void setTargetObject(String targetObject) {
this.targetObject = targetObject;
}
public void setTargetMethod(String targetMethod) {
this.targetMethod = targetMethod;
}
}