sprign中的监听器。

来源:互联网 发布:spectrum 网络 编辑:程序博客网 时间:2024/05/28 16:14

使用spring中的监听器 ,需要实现ApplicationListener接口。


public class StartUpListener implements ApplicationListener<ApplicationEvent>{public static boolean isStart = false;@Overridepublic void onApplicationEvent(ApplicationEvent event) {if(isStart)return ;if(event instanceof ContextStartedEvent)System.out.println("容器启动..................................................");isStart = true ;}}

可以通过判断event的类型,来坚挺不同类型的时间。

判断event类型的方法  可以用 if(event instanceof UserEvent) ; 这种方式判断

原创粉丝点击