0

我在我的 JSP Struts/Hibernate 应用程序的不同 java 文件中加入了石英调度程序。我的执行方法如下所示:

public void execute(JobExecutionContext jExeCtx) throws JobExecutionException {
       try {
        userDetailManager = new UserDetailManagerImpl();
        userDetailManager.sendMailTxnDetailsEveryNight();
    } catch (ApplicationException ex) {
        java.util.logging.Logger.getLogger(JobClass.class.getName()).log(Level.SEVERE, null, ex);
    }
 }

然后我调用 sendMailTxnDetailsEveryNight 方法,看起来像:

public void sendMailTxnDetailsEveryNight() throws ApplicationException{
    List<RemittanceTransactionBean> rBean = remittanceTransactionDao.getTodayTxnSummary();
return rBean;
}

我在给定点收到 nullpointerException :

java.lang.NullPointerException
at com.mtmrs.business.user.impl.UserDetailManagerImpl.sendMailTxnDetailsEveryNight(UserDetailManagerImpl.java:754)
at com.mtmrs.util.common.JobClass.execute(JobClass.java:44)

我需要如何调用 getTodayTxnSummary(); 这样我就不会收到任何错误。我也在 applicationContext 中定义了 remittanceTransactionDao:

<bean id="userDetailManager" parent="abstractTxDefinition">
    <property name="target">
        <bean class="com.mtmrs.business.user.impl.UserDetailManagerImpl">
        <property name="remittanceTransactionDao" ref="remittanceTransactionDao"></property>
        </bean>
    </property>
</bean>

我调试了一下,remittanceTransactionDao 为空。在调用方法 remittanceTransactionDao 之前,我还尝试了以下设置。这样,在 sendMailTxnDetailsEveryNight 中使用的会话变量为空。我被困在这里。

remittanceTransactionDao = new RemittanceTransactionDaoHibernate(RemittanceTransaction.class);
4

1 回答 1

0

我删除了这些类并在我的应用程序上下文 Dao.xml 中配置了以下内容。

<bean name="runMeJob" class="org.springframework.scheduling.quartz.JobDetailBean">

    <property name="jobClass" value="com.mtmrs.util.common.RunMeJob" />

    <property name="jobDataAsMap">
        <map>
            <entry key="userDetailManager" value-ref="userDetailManager" />
        </map>
    </property>

</bean>
<bean id="cronTrigger"
      class="org.springframework.scheduling.quartz.CronTriggerBean">

    <property name="jobDetail" ref="runMeJob" />
    <property name="cronExpression" value="0 0 10,12,14,16,18,20,22,23 * * ?" />
</bean>

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    <property name="jobDetails">
        <list>
            <ref bean="runMeJob" />
        </list>
    </property>

    <property name="triggers">
        <list>
            <ref bean="cronTrigger" />
        </list>
    </property>
</bean>

然后我删除了关于石英实现代码的所有内容,无论我试图做什么,并添加了这个类:

package com.mtmrs.util.common;
import com.mtmrs.business.user.UserDetailManager;
import com.mtmrs.util.logger.MTMRSLogger;
import com.mtmrs.util.logger.ApplicationException;
import java.util.logging.Level;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;


public class RunMeJob extends QuartzJobBean {

UserDetailManager userDetailManager;

public UserDetailManager getUserDetailManager() {
    return userDetailManager;
}

public void setUserDetailManager(UserDetailManager userDetailManager) {
    this.userDetailManager = userDetailManager;
}

@Override
protected void executeInternal(JobExecutionContext context)
        throws JobExecutionException {
    System.out.print("Entering Class: Job Class , method: execute");
    try {
        userDetailManager.sendMailTxnDetailsEveryNight();
    } catch (ApplicationException ex) {
        java.util.logging.Logger.getLogger(RunMeJob.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.print("Exiting Class: Job Class , method: execute");

}

}

我也将石英罐的版本降级为 1.x。我需要使用 userDetailManager(即 sendMailTxnDetailsEveryNight)对象中的方法作为触发器中指定的每 2 小时运行一次的作业。

基本上我点击了这个链接:Mykong 希望这可以对某人有所帮助。

于 2013-04-25T04:32:48.310 回答