如何编写一个 cron 表达式,在 spring/java 的工作日从 9:30 到 4:00 am 每 5 分钟运行一次?
How to write a cron expression that runs every 5 mins from 9:30 to 4:00 am on weekdays in spring/java?
我有一个 Spring Boot
应用程序,它有一个 cron
表达我想 运行 在周一至周五 9:30 上午到 4:00 下午每 5 分钟一班。
但是看起来 cron
表达式不正确。
application.properties
job.signal.cron=0 0/5 9:30-16 * * MON-FRI
启动时出错:
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'findSignal': For input string: "9:30" '9:30-16' in cron expression "0 0/5 9:30-16 * * MON-FRI"
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:511) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$null(ScheduledAnnotationBeanPostProcessor.java:374) ~[spring-context-5.3.3.jar:5.3.3]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:374) ~[spring-context-5.3.3.jar:5.3.3]
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[na:na]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:373) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:444) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.3.jar:5.3.3]
... 21 common frames omitted
你可以试试这个
0 30-55/5 9 * * MON-FRI
0 */5 10-15 * * MON-FRI
0 0 16 * * MON-FRI
我有一个 Spring Boot
应用程序,它有一个 cron
表达我想 运行 在周一至周五 9:30 上午到 4:00 下午每 5 分钟一班。
但是看起来 cron
表达式不正确。
application.properties
job.signal.cron=0 0/5 9:30-16 * * MON-FRI
启动时出错:
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'findSignal': For input string: "9:30" '9:30-16' in cron expression "0 0/5 9:30-16 * * MON-FRI"
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:511) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$null(ScheduledAnnotationBeanPostProcessor.java:374) ~[spring-context-5.3.3.jar:5.3.3]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:374) ~[spring-context-5.3.3.jar:5.3.3]
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[na:na]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:373) ~[spring-context-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:444) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.3.3.jar:5.3.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.3.jar:5.3.3]
... 21 common frames omitted
你可以试试这个
0 30-55/5 9 * * MON-FRI
0 */5 10-15 * * MON-FRI
0 0 16 * * MON-FRI