Spring Boot-based applications create timed tasks don't be too easy, add a @configuration @EnableScheduling annotation to a class, and then add @scheduled (cron = "${" to the method that the class needs to execute regularly. Case.phase.cron} ") annotation. It's OK.
${case.phase.cron} indicates that Case.phase.cron is taken from the application configuration file Application.properties, or from Config-server.
Importjava.util.List;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;Importorg.springframework.beans.factory.annotation.Autowired;Importorg.springframework.context.annotation.Configuration;Importorg.springframework.scheduling.annotation.EnableScheduling;Importorg.springframework.scheduling.annotation.Scheduled;/*** Timed Task * to invoke the standard interface of the job status query **/@Configuration @enablescheduling Public classCasephasetaskservice {Private Static FinalLogger Logger = Loggerfactory.getlogger (casephasetaskservice.class); @Scheduled (Cron= "${case.phase.cron}") Public voidExecscheduledtask () {Logger.info ("Task start ..."); Logger.info ("Task is over!"); }}
Spring Boot Create a timed task