在启动期间是否有多个 Spring bean 一次侦听 ApplicationStartedEvent?

问题描述

在启动过程中,有三个处理程序将自己注册到接口注册表(Set<Interfaces>

下面是一个类的例子

@Configuration
public class CardAdapterHandler implements PaymentAdapterListener {

    @Autowired
    private InterfaceRegistry interfaceRegistry;

    @EventListener(ApplicationStartedEvent.class)
    public void init() {
        interfaceRegistry.setListener(this);
    }
}

二级

@Configuration
public class CashAdapterHandler implements PaymentAdapterListener {

    @Autowired
    private InterfaceRegistry interfaceRegistry;

    @EventListener(ApplicationStartedEvent.class)
    public void init() {
        interfaceRegistry.setListener(this);
    }
}

等等..

SpringBoot - 2.2.10.RELEASE

既然多个类都在监听ApplicationStartedEvent,那么多个Spring bean会不会同时监听ApplicationStartedEvent? 应用程序启动时是否有可能发生并发修改异常?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)