0. 假设已配置好 SSM 环境
1. 配置文件
有划分配置文件的话建议添加在 spring-service.xml 中,没有的话就放在可以生效的地方
spring-service.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task
https://www.springframework.org/schema/task/spring-task.xsd">
<!-- 扫描 service 下的包 -->
<!-- service 为定时任务所在的包 -->
<!-- utils 为 Redis 工具类所在的包 -->
<context:component-scan base-package="com.qg.service"/>
<context:component-scan base-package="com.qg.utils

本文介绍如何在已配置好的SSM环境中,利用Spring的@Scheduled注解配合Redis工具类,实现定时将Redis缓存数据写入数据库。详细讲解了cron表达式的配置,并给出实战例子。
最低0.47元/天 解锁文章
1092

被折叠的 条评论
为什么被折叠?



