如何解决在启动期间是否有多个 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 举报,一经查实,本站将立刻删除。