![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
定时器
差一步距离
这个作者很懒,什么都没留下…
展开
-
java实现服务器启动时,自动启动定时器
DataMoveTask类实现定时任务: 该项目是基于Spring-boot构建的,添加此注解@Component 能够保证在服务器启动的时候运行该类。无需设置web.xml import org.springframework.stereotype.Component; import javax.servlet.ServletContextEvent; import javax.ser...原创 2019-04-18 14:17:57 · 3039 阅读 · 0 评论 -
Timer定时器中的service不能用的解决办法
问题:service在平常的controller中可以用,但是在定时器的run方法中不能用。 原因:定时器继承了TimerTask之后,在定时器调用此方法后会直接执行execute方法,来不及执行@Autowired标注进行注入。 引入ApplicationContextUtil的工具类: import org.springframework.beans.BeansException; ...原创 2019-04-18 10:32:31 · 938 阅读 · 0 评论