配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- quartz start-->
<!-- 要调用的工作类 -->
<bean id="quartzJob" class="PublishSqlQuartz"></bean>
<!-- 定义调用对象和调用对象的方法 -->
<bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="quartzJob"/>
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>execute</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 * * ?</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>
<!--quartz end -->
</beans>
package quartz;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.jeecgframework.core.util.ResourceUtil;
/**
* 定时发布SQl模版方法
*/
public class PublishSqlQuartz{
public void execute() throws IOException{
URL url = new URL (“http://localhost:8080/”+"articleSqlStaticPageController.do?ftpFileALL");
URLConnection con=url.openConnection();
BufferedReader r = new BufferedReader(new InputStreamReader(con.getInputStream(),"UTF-8"));
r.readLine();
}
}
/**
* 用于定时同步
*/
@RequestMapping(params = "ftpFileALL")
@ResponseBody
public String ftpFileALL(ArticlePage page, HttpServletRequest request) {
return null;
}