- * 由{@link org.springframework.beans.factory.BeanFactory} 实现,通过工具开放API - *
- * 更新: shadow 2021-07-29 17:20:44 增加自动注入,修复注册bean无法反向注入的问题
- *
- * @param
- * 将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!");
- }
- }
-
- /**
- * 发布事件
- *
- * @param event 待发布的事件,事件必须是{@link ApplicationEvent}的子类
- * @since 5.7.12
- */
- public static void publishEvent(ApplicationEvent event) {
- if (null != applicationContext) {
- applicationContext.publishEvent(event);
- }
- }
-
- /**
- * 发布事件
- * Spring 4.2+ 版本事件可以不再是{@link ApplicationEvent}的子类
- *
- * @param event 待发布的事件
- * @since 5.7.21
- */
- public static void publishEvent(Object event) {
- if (null != applicationContext) {
- applicationContext.publishEvent(event);
- }
- }
-}