使用配置文件控制定时任务的注解

@Component
@EnableScheduling
@PropertySource("classpath:config/sftp.properties")
public class TimedTask {
@Resource
private SFTPProp sftpProp;
@Resource
private SaveImpl save;

@Scheduled(cron = "${timedTask}")
public void downloadTask() {
System.out.println("定时任务自动启动,当前时间:" + new Date());
System.out.println("IP:" + sftpProp.getIP());
System.out.println("Port:" + sftpProp.getPort());
System.out.println("Username:" + sftpProp.getUsername());
System.out.println("Password:" + sftpProp.getPassword());
System.out.println("remoteDownloadDir:" + sftpProp.getRemoteDownloadDir());
  }
}

@PropertySource("classpath:config/sftp.properties")

@Scheduled(cron = "${timedTask}")

在使用jar包运行程序时,会读取不到外部配置,将配置文件名改为application.properties后问题解决
posted @ 2021-01-12 16:03  缀满繁星的夜空  阅读(173)  评论(0)    收藏  举报