ssh+quartz报
空指针异常用quartz实现自动发送邮件的功能,整合到ssh框架中去报
空指针异常。
action:package action;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import service.MailService;
public class SendEmailJob extends QuartzJobBean{
private MailService mailService;
// public MailService getMailService() {
// return mailService;
// }
public void setMailService(MailService mailService) {
this.mailService = mailService;
}
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
try{
//System.out.println("mailService:"+mailService);
this.mailService.sendEmail();
}catch (Exception e) {
e.printStackTrace();
}
}
}
service & serviceImpl
public interface MailService {
void sendEmail();
String queryEmailBytId(int tId);
}
package service.impl;
import java.util.List;
import service.MailService;
import util.MailUtil;
import dao.SendEmailDao;
public class MailServiceImpl implements MailService{
private SendEmailDao sendEmailDao;
public SendEmailDao getSendEmailDao() {
return sendEmailDao;
}
public void setSendEmailDao(SendEmailDao sendEmailDao) {
this.sendEmailDao = sendEmailDao;
}
public void sendEmail() {
List l = sendEmailDao.queryEmail();
for(int i=0;i<l.size();i++){
String email = (String) l.get(i);
try {
MailUtil util = new MailUtil();
util.sendMail(email);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public String queryEmailBytId(int tId) {
return this.sendEmailDao.queryEmailBytId(tId);
}
}
dao & daoImpl
package dao;
import java.util.List;
public interface SendEmailDao {
List queryEmail();
String queryEmailBytId(int tId);
}
package dao.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import dao.SendEmailDao;
import util.HibernateSessionFactory;
public class SendEmailDaoImpl extends HibernateDaoSupport implements SendEmailDao{
public List queryEmail(){
List l = new ArrayList();
Session session = HibernateSessionFactory.getSession();
try{
session.beginTransaction().begin();
List list = session.createSQLQuery("select user_email from user where user_id in " +
"(select t_user_id from task where str_to_date(t_finish_time,'%m/