logback-spring.xml cron定时器配置给出示例
时间: 2023-03-07 19:30:10 浏览: 76
在 logback-spring.xml 中配置 cron 定时器的示例可以如下所示:
<task:scheduled-tasks>
<task:scheduled ref="cronTask" method="execute" cron="0 0 0 * * ?" />
</task:scheduled-tasks>
相关问题
logback-spring.xml 配置cron定时器给出完整的logback-spring.xml配置
<configuration>
<springProfile name="production">
<timestamp key="byDay" datePattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/appName-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
</springProfile> <springProfile name="cron">
<timestamp key="byCron" datePattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/logs/appName-cron-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<cronTriggeringPolicy class="ch.qos.logback.core.rolling.CronTriggeringPolicy">
<cronExpression>0 0 0 * * ?</cronExpression>
</cronTriggeringPolicy>
</springProfile>
</configuration>
logback-spring.xml 定时器配置给出示例
示例:
```
<configuration>
<property name="Name" value="MyApp" />
<timers>
<timer name="MyTimer" class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="delay" value="5000" />
<property name="period" value="10000" />
<property name="fixedRate" value="true" />
</timer>
</timers>
</configuration>
```
这是logback-spring.xml定时器的配置示例,它将在延迟5秒后开始,每10秒执行一次,并且使用fixedRate属性设置为true。
阅读全文