ITeye博客

spring

共 2 篇文章

spring中监听事件

spring里的事件为bean与bean间消息通信提供了支持,我们希望在一个bean处理完一个任务后,通知其他的bean做相应的事,此时就需要另外的Bean去监听当前bean所发生的事件 定义spring的事件需做以下几件事: 自定义事件,继承ApplicationEvent 定义一个事件监听器,实现ApplicationListener 使用容器ApplicationContext来发布事件 一.自定义事件 package com.zgw.event; import org.springframework.context.ApplicationEvent; public class Eve…

2018-08-31 23:07 · spring · Java · Spring · 监听器

Spring中实现定时任务

spring中通过@EnableScheduling来开启对定时任务的支持 然后通过@Scheduled声明,它支持多种类型的定时任务,包含cron,fixDelay,fixRate等 实例如下: 定时任务执行类 package com.zgw.taskscheduler; import java.text.SimpleDateFormat; import java.util.Date; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Servi…

2018-08-31 22:11 · spring · Java · Spring · 定时任务