@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后问题解决