quartz定时器问题

youfeng445 2010-12-29 01:21:13

配置文件
<bean id="jobDetailBean" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.dne.cn.framework.report.timmer.TimerTask</value>
</property>

</bean>
<bean id="cronReportTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetailBean" />
<property name="cronExpression">
<value>0 02 13 ? * WED </value>
</property>
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronReportTrigger" />
</list>
</property>
</bean>





public class TimerTask extends QuartzJobBean {
@Autowired
private IUserService userService;
@Autowired
private ISmsInventoryInfoService smsInventoryInfoServic;
public void setUserService(IUserService userService) {
this.userService = userService;
}
public void setSmsInventoryInfoServic(
ISmsInventoryInfoService smsInventoryInfoServic) {
this.smsInventoryInfoServic = smsInventoryInfoServic;
}

@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {

List<Long> tpsIds = smsInventoryInfoServic.getAllTps();
UserModel um = null;
List<Long> tmList = new ArrayList<Long>();
List<Long> crmList = new ArrayList<Long>();

for (Long tpsId : tpsIds) {
try {
List<String> emailAddresses = getEmail(tpsId);
um = userService.getEntityById(tpsId);// 查询出tm
if (um != null) {
String path = smsInventoryInfoServic.createExcel(um, null,
null);
if (um != null && !tmList.contains(um.getParentId()))
tmList.add(um.getParentId());
um = userService.getEntityById(um.getParentId());// crm
if (um != null && !crmList.contains(um.getParentId()))
crmList.add(um.getParentId());
// sendMail.send(emailAddresses, path, "一周报告", "一周报告");
// Thread.sleep(1000 * 20);
}

} catch (Exception e) {
e.printStackTrace();
continue;
}
}

}

private List<String> getEmail(Long tpsId) {
List<String> emailAddresses = new ArrayList<String>();
UserModel um = userService.getEntityById(tpsId);
if (um != null && um.getUserEmail() != null)
emailAddresses.add(um.getUserEmail());
return emailAddresses;
}

}



现在2个注入的类都为空,请问下,应该怎么写,这2个类才能注入进来
...全文
90 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeky_zhang2013 2010-12-29
  • 打赏
  • 举报
回复
一般在spring中都是依赖注入的,估计是配置文件的问题
goodsun00 2010-12-29
  • 打赏
  • 举报
回复
我提下 TimerTask

bean id = TimerTask class=具体类
property = userService
ref = 注入UserService的id
property = smsInventoryInfoServic
ref = 注入SmsInventoryInfoService的id

大概这样 ,你整整 写好
rechi_228 2010-12-29
  • 打赏
  • 举报
回复
<!-- Timer -->
<bean id="remindTimer" class="com.ear.oams.timer.service.RemindTimer" autowire="byName">
<property name="restrictionHelper" ref="restrictionHelper"/>
<property name="mailService" ref="mailService"/>
<property name="supman" value="${supman}"></property>
</bean>
<bean id="remindJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="remindTimer" />
<property name="targetMethod" value="messageRemind" />
<property name="concurrent" value="false" />
</bean>

<bean id="remindJobDetail1"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="remindTimer" />
<property name="targetMethod" value="updateTeAndSt" />
<property name="concurrent" value="false" />
</bean>

<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="remindJobDetail" />
<property name="cronExpression" value="0 0 5 * * ?" /><!-- 每天早上5点钟执行 -->
</bean>

<bean id="cronTrigger1" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="remindJobDetail1" />
<property name="cronExpression" value="1 0 0 ? * 4,7" /><!-- 周三周六凌晨执行 -->
</bean>
<!-- 调度器 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
<ref bean="cronTrigger1" />
</list>
</property>
</bean>

不知道能不能够帮到你
zn85600301 2010-12-29
  • 打赏
  • 举报
回复
这个你要在你的Job配置文件里面加上呀

但是你这种job的配置方法好像不能添加注入
你直接自己读取配置文件获取service对象就行了
或者用另外一种job的实现方法 不继承QuartzJobBean

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧