日期:2014-05-17  浏览次数:20920 次

SpringMVC中quartz的使用问题
我要用spring的quartz去实现任务调度,每隔一分钟调用一次后台方法。具体代码如下:
quartz配置文件applicationContext.xml:
XML code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <!-- 要调用的工作类 -->
    <bean id="leaveQuartz" class="util.LeaveQuartz"></bean>
    
    <!-- 定义调用对象和调用对象的方法 -->
    <bean id="jobtask"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <!-- 调用的类 -->
        <property name="targetObject">
            <ref bean="leaveQuartz" />
        </property>
        <!-- 调用类中的方法 -->
        <property name="targetMethod">
            <value>quartzStart</value>
        </property>
    </bean>
    <!-- 定义触发时间 -->
    <bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref bean="jobtask" />
        </property>
        <!-- cron表达式 -->
        <property name="cronExpression">
            <value>0 0/1 9-19 * * ?</value>
        </property>
    </bean>
    <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序  -->
    <bean id="startQuertz" lazy-init="false" autowire="no"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="doTime" />
            </list>
        </property>
    </bean>

</beans>



要调用的类:
LeaveQuartz.java
Java code

@Controller
public class LeaveQuartz
{
    private EmployeeLeaveService employeeLeaveService;

    @Resource(name = "employeeLeaveService")
    public void setEmployeeLeaveService(EmployeeLeaveService employeeLeaveService)
    {
        this.employeeLeaveService = employeeLeaveService;
    }
    
    public void quartzStart()
    {
        updateLeaveingsNumber();
    }
    
    public void updateLeaveingsNumber()
    {
        double leaveingsNumber = HRConstants.MATH_ZORE;
        employeeLeaveService.getEmployeeLeaveMaxId();
    }
}



我把applicationContext.xml配置在web.xml中,让任务调度随tomcat启动时调用,单不知道为什么LeaveQuartz.java类中employeeLeaveService总是为null。
忘高手能解答.....
谢谢了。


------解决方案--------------------
我的代码就是调用的service层得代码呀 
<bean id="job" class="com.wb.sms.service.imp.SmsSendServiceImp">

service实现类:
public class SmsSendServiceImp implements ISmsSendService {

汗!!!!!!!!!!!!!!!!