Search in sources :

Example 1 with DefaultSingletonBeanRegistry

use of org.springframework.beans.factory.support.DefaultSingletonBeanRegistry in project hutool by looly.

the class SpringUtil method unregisterBean.

/**
 * 注销bean
 * <p>
 * 将Spring中的bean注销,请谨慎使用
 *
 * @param beanName bean名称
 * @author shadow
 * @since 5.7.7
 */
public static void unregisterBean(String beanName) {
    final ConfigurableListableBeanFactory factory = getConfigurableBeanFactory();
    if (factory instanceof DefaultSingletonBeanRegistry) {
        DefaultSingletonBeanRegistry registry = (DefaultSingletonBeanRegistry) factory;
        registry.destroySingleton(beanName);
    } else {
        throw new UtilException("Can not unregister bean, the factory is not a DefaultSingletonBeanRegistry!");
    }
}
Also used : DefaultSingletonBeanRegistry(org.springframework.beans.factory.support.DefaultSingletonBeanRegistry) UtilException(cn.hutool.core.exceptions.UtilException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 2 with DefaultSingletonBeanRegistry

use of org.springframework.beans.factory.support.DefaultSingletonBeanRegistry in project spring-cloud-stream by spring-cloud.

the class AbstractMessageChannelBinder method destroyErrorInfrastructure.

private void destroyErrorInfrastructure(ProducerDestination destination) {
    String errorChannelName = errorsBaseName(destination);
    String errorBridgeHandlerName = getErrorBridgeName(destination);
    MessageHandler bridgeHandler = null;
    if (getApplicationContext().containsBean(errorBridgeHandlerName)) {
        bridgeHandler = getApplicationContext().getBean(errorBridgeHandlerName, MessageHandler.class);
    }
    if (getApplicationContext().containsBean(errorChannelName)) {
        SubscribableChannel channel = getApplicationContext().getBean(errorChannelName, SubscribableChannel.class);
        if (bridgeHandler != null) {
            channel.unsubscribe(bridgeHandler);
            ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory()).destroySingleton(errorBridgeHandlerName);
        }
        ((DefaultSingletonBeanRegistry) getApplicationContext().getBeanFactory()).destroySingleton(errorChannelName);
    }
}
Also used : DefaultSingletonBeanRegistry(org.springframework.beans.factory.support.DefaultSingletonBeanRegistry) MessageHandler(org.springframework.messaging.MessageHandler) AbstractMessageHandler(org.springframework.integration.handler.AbstractMessageHandler) AbstractSubscribableChannel(org.springframework.integration.channel.AbstractSubscribableChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel)

Aggregations

DefaultSingletonBeanRegistry (org.springframework.beans.factory.support.DefaultSingletonBeanRegistry)2 UtilException (cn.hutool.core.exceptions.UtilException)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 AbstractSubscribableChannel (org.springframework.integration.channel.AbstractSubscribableChannel)1 AbstractMessageHandler (org.springframework.integration.handler.AbstractMessageHandler)1 MessageHandler (org.springframework.messaging.MessageHandler)1 SubscribableChannel (org.springframework.messaging.SubscribableChannel)1