Inconsistent ApplicationEventMulticaster state after removing ApplicationListener implemented by FactoryBean
When a FactoryBean directly implements ApplicationListener:
• It is registered using &beanName
• During destruction, only removeApplicationListener(instance) is successed
• The applicationListenerBeans entry for "&beanName" does not seem to be removed
ApplicationListenerDetector.java
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) {
if (bean instanceof ApplicationListener<?> applicationListener) {
try {
ApplicationEventMulticaster multicaster = this.applicationContext.getApplicationEventMulticaster();
multicaster.removeApplicationListener(applicationListener);
// remove failed, because the beanName without & prefix
multicaster.removeApplicationListenerBean(beanName);
}
catch (IllegalStateException ex) {
// ApplicationEventMulticaster not initialized yet - no need to remove a listener
}
}
}