package main.java.com.sunyard;
import main.java.com.sunyard.util.DateUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.File;
/**
* @author jizhongyu Email:jizhongyu1994@163.com
* @description
* @since 2020/2/14 11:30 下午
*/
@Component
@EnableScheduling
@Async
//@ImportResource("")
@PropertySource("classpath:/main/resource/folerAttribute.properties")
public class SaticScheduleTask {
private final Log logger = LogFactory.getLog(this.getClass());
// @Scheduled(cron = "0/5 * * * * ?")
// public void configureTasks(){
// // TODO 从文件中拿取路径
// String fileDir = "/Users/apache/Desktop/test";
// logger.info("定时任务1执行开始----time:"+date);
// this.deleteFolder(fileDir);
// logger.info("定时任务1执行结束----time:"+date);
// }
@Value("${filePath}")
private String filePath;
@Scheduled(cron = "0/5 * * * * ?")
public void configureTasks2(){
logger.info("定时任务执行开始----time:"+DateUtil.getDefaultCurrentDateTime());
String[] filePathArray = filePath.split(",");
for(String path : filePathArray){
this.deleteFolder(path);
}
logger.info("定时任务执行结束----time:"+DateUtil.getDefaultCurrentDateTime());
}
public void deleteFolder(String path) {
logger.info("清理任务path:"+path+"----starttime:"+DateUtil.getDefaultCurrentDateTime());
// if(path.isEmpty()){
// logger.info("找不到该文件夹");
// return;
// }
File srcFolder = new File(path);
File[] fileArray = srcFolder.listFiles();
if (fileArray != null) {
for (File file : fileArray) {
// isDirectory()方法是判断文件是文件夹还是一个文件
if (file.isDirectory()) {
//如果是文件夹则在此递归本方法
deleteFolder(file.getAbsolutePath());
} else {
System.out.println(file.getName() + ":" + file.delete() +"成功删除文件");
}
}
System.out.println(srcFolder.getName() + ":" + srcFolder.delete() +"成功删除文件夹");
}
logger.info("清理任务path:"+path+"----endtime:"+DateUtil.getDefaultCurrentDateTime());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
springBootNoMaven.zip
共78个文件
jar:30个
class:14个
xml:7个
需积分: 24 16 下载量 136 浏览量
2020-02-17
23:53:43
上传
评论
收藏 12.07MB ZIP 举报
温馨提示
不使用maven环境,创建springboot项目,实现了定时任务功能。简单的小demo。 不使用网络环境,适合银行内密闭环境使用。纯手敲,感谢支持
资源推荐
资源详情
资源评论
收起资源包目录
task_delete_folder.zip (78个子文件)
task_delete_folder
.project 1KB
.DS_Store 6KB
src
.DS_Store 6KB
test
main
resource
folerAttribute.properties 105B
webapp
java
com
sunyard
pojo
FolderPath.java 490B
util
DateUtil.java 3KB
Application.java 860B
SaticScheduleTask.java 3KB
AsyncConfig.java 1KB
target
main
resource
folerAttribute.properties 105B
java
com
sunyard
SaticScheduleTask.class 3KB
pojo
FolderPath.class 997B
Application.class 1KB
util
DateUtil.class 2KB
AsyncConfig.class 1KB
WebRoot
WEB-INF
.DS_Store 6KB
classes
test
HelloSpringBoot.class 2KB
lib
jackson-annotations-2.8.4.jar 54KB
spring-aop-4.3.4.RELEASE.jar 371KB
spring-boot-starter-logging-1.4.2.RELEASE.jar 2KB
spring-expression-4.3.4.RELEASE.jar 257KB
tomcat-embed-el-8.5.6.jar 234KB
tomcat-embed-core-8.5.6.jar 2.85MB
spring-core-4.3.4.RELEASE.jar 1.06MB
spring-boot-1.4.2.RELEASE.jar 643KB
spring-boot-starter-web-1.4.2.RELEASE.jar 2KB
spring-beans-4.3.4.RELEASE.jar 743KB
logback-classic-1.1.7.jar 297KB
spring-boot-starter-tomcat-1.4.2.RELEASE.jar 2KB
jackson-core-2.8.4.jar 274KB
jboss-logging-3.3.0.Final.jar 65KB
validation-api-1.1.0.Final.jar 62KB
tomcat-embed-websocket-8.5.6.jar 236KB
jul-to-slf4j-1.7.21.jar 4KB
spring-web-4.3.4.RELEASE.jar 795KB
snakeyaml-1.17.jar 267KB
hibernate-validator-5.2.4.Final.jar 688KB
jackson-databind-2.8.4.jar 1.18MB
classmate-1.3.3.jar 63KB
logback-core-1.1.7.jar 460KB
spring-context-4.3.4.RELEASE.jar 1.08MB
slf4j-api-1.7.21.jar 40KB
spring-boot-starter-1.4.2.RELEASE.jar 4KB
spring-boot-autoconfigure-1.4.2.RELEASE.jar 946KB
log4j-over-slf4j-1.7.21.jar 23KB
jcl-over-slf4j-1.7.21.jar 16KB
spring-webmvc-4.3.4.RELEASE.jar 892KB
deleteFolderTask.xml 892B
.DS_Store 6KB
index.jsp 834B
META-INF
MANIFEST.MF 39B
.idea
libraries
lib.xml 3KB
misc.xml 258B
uiDesigner.xml 9KB
workspace.xml 7KB
sonarlint
issuestore
8
9
897e8e050b0bdc59f75d8123c04294828c5b9510 318B
e
5
e5a29f843b3365e172c3d4328af185d0e71ca570 0B
4
a
4aa1fc2216a96b85490d654b2f012b9cea854db8 0B
index.pb 252B
modules.xml 268B
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 501B
.jsdtscope 522B
.classpath 686B
TaskSpringBoot.iml 611B
out
production
TaskSpringBoot
com
sunyard
SaticScheduleTask.class 3KB
pojo
FolderPath.class 977B
Application.class 1KB
util
DateUtil.class 2KB
AsyncConfig.class 1KB
META-INF
TaskSpringBoot.kotlin_module 16B
testSpringBoot
test
SaticScheduleTask.class 967B
Application.class 1KB
AsyncConfig.class 1KB
META-INF
testSpringBoot.kotlin_module 16B
共 78 条
- 1
资源评论
六年级叔叔
- 粉丝: 13
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功