12345678910111213141516171819202122232425262728293031 |
- package com.nosum.system.schedule;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.mongodb.core.MongoTemplate;
- import org.springframework.data.mongodb.core.query.Criteria;
- import org.springframework.data.mongodb.core.query.Query;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import java.time.LocalDateTime;
- /**
- * 定时清理过期 TOKEN
- *
- * @author Young
- */
- @Component
- @Slf4j
- public class SchedulerTask {
- @Autowired
- private MongoTemplate mongoTemplate;
- @Scheduled(cron = "0 0/1 * * * ?")
- private void scanToken() {
- log.debug(" {} 扫描过期Token", LocalDateTime.now());
- mongoTemplate.remove(Query.query(Criteria.where("expireTime").lte(LocalDateTime.now())));
- }
- }
|