spring事件可以通过实现接口ApplicationListener来定义事件侦听器,在onApplicationEvent中写处理事件的逻辑;但这回调是同步的,若想异步去调用,可以通过加@Async注解,并打开任务调用线程来实现。spring 配置文件中加上:
<!-- 任务调度器 -->
<task:scheduler id="scheduler" pool-size="10"/>
<!-- 任务执行器 -->
<task:executor id="executor" pool-size="10"/>
<!--开启注解调度支持 @Async @Scheduled-->
<task:annotation-driven executor="executor" scheduler="scheduler" />