Advertisement

基于Spring的SmartApplicationListener实现业务解耦功能

阅读量:

一、SmartApplicationListener介绍

Spring框架中的ApplicationEvent及其对应的监听器机制,为事件的监听与发布订阅功能提供了实现途径,其内部采用观察者模式进行设计,有助于降低业务系统间的耦合度,从而提升系统的可扩展性、可复用性以及可维护性。

Spring框架针对ApplicationEvent与监听器提供了三种实现方式:

  • 通过@EventListener注解进行配置;
  • 实现ApplicationListener接口;
  • 实现SmartApplicationListener接口;

接下来将对SmartApplicationListener的使用方式进行介绍。该接口继承了ApplicationListener与Ordered接口,具备事件监听功能的同时还支持排序操作。

在这里插入图片描述

SmartApplicationListener包含两个具体的功能实现方式:

复制代码
    /** *  指定支持哪些类型的事件
     */
    boolean supportsEventType(Class<? ex

全部评论 (0)

还没有任何评论哟~