关于定时任务的xml,一定要单独创建(里面就放标红的部分和spring的基础部分,项目里一般都有),不然容易出现多次启动定时任务
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/beans http://www
在SSM项目中实现定时任务,需要将定时任务配置单独,防止重复启动。通过在springmvc.xml添加spring-task相关配置,启用注解驱动的定时任务。创建TimerTask类,使用@Scheduled注解定义cron表达式来控制任务执行时间,例如每晚22点30执行。cron表达式的正确配置是确保任务按预期运行的关键。
订阅专栏 解锁全文
726

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



