springboot作定进任务,比较简单。java
在applicatoin上加上注解 @EnableSchedulingspring
在本身的方法上,加上 @Scheduled(fixedDelay = 10*1000 ) 就能够每次执行完后,隔10秒,执行下一次了。 可是,如今我但愿这个时间可配置springboot
我在application.proterties中增长了自定义的一项。mail.schedule=10000bash
在执行类中,增长 @ConfigurationProperties(prefix = "mail"),在执行方法上,改成 @Scheduled(fixedDelayString = "${mail.schedule}")app
kotlin的写法,要在$前加,而后fixedDelay 要改成fixedDelayStringspa
@Component
@ConfigurationProperties(prefix = "mail")
class ScheduledTask {
@Autowired
lateinit var mailInboxService: MailReceiveUtils
private val logger = LoggerFactory.getLogger(javaClass)
@Scheduled(fixedDelayString = "\${mail.schedule}")
fun receive() {
MailServerApplication.data.forEach({
mailInboxService.resceive(it)
}
)
}
}
复制代码