日期:2014-05-19  浏览次数:20822 次

bena装载spring定时器时出问题
这是我在web-inf/springtimer.xml中的信息
XML code
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
           
    <bean id="timer" class="com.timeftp.Timer">
        <property name="invoketf" value="true"/>
    </bean>
    
    <bean id="reportTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="timer" />
    <property name="targetMethod" value="callFTP" />
    <property name="concurrent" value="false" />     
    </bean>
    
    <bean id="cronTigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="reportTask" />
        <property name="cronExpression" value="0 0 23 * * ?"/>
    </bean>
    
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
            <ref bean="cronTigger"/>
            </list>
        </property>
    </bean>
</beans>


web.xml中的信息

XML code

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/springtimer.xml</param-value>
    </context-param>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
</web-app>




这是我在com.timeftp包下的Timer类
Java code
package com.timeftp;

import com.ftpconnect.FtpID;
import com.ftpconnect.FtpTest;

public class Timer {
    private boolean invoketf;

    /**
     * 连接FTP文件下载删除
     */
    public void callFTP() {
        FtpID fid = new FtpID();
        System.out.println("自动开始");
        fid.inject("ftp.properties");
        FtpTest.loginFTP(fid.getftp(), fid.getPost(), fid.getUser(), fid
                .getPassword());
        FtpTest.downfile(fid.getFilepath());
        FtpTest.deleteFile();
        FtpTest.closeFTP();
        System.out.println("自动结束");
    }
    
    /**
     *   TOMCAT启动时是否立即在FTP上下载文件和删除文件
     * @param invoketf
     */
    public void setInvoketf(boolean invoketf) {
        this.invoketf = invoketf;
        if (this.invoketf) {
            FtpID