1。这个问题偶尔遇到。再起启动就不报错了。而然昨天报错了很久。spring吞掉异常了。只好一步步调试。发现在创建bean的时候,
会调用 AbstractApplicationContext 类的
protected void assertBeanFactoryActive() { if (!this.active.get()) { if (this.closed.get()) { throw new IllegalStateException(getDisplayName() + " has been closed already"); } else { throw new IllegalStateException(getDisplayName() + " has not been refreshed yet"); } } }
active的值改成false了。
修改方法是
protected void cancelRefresh(BeansException ex) { this.active.set(false); }
调用方法是
@Override public void refresh() throws BeansException, IllegalStateException { synchronized (this.startupShutdownMonitor) { // Prepare this context for refreshing. prepareRefresh(); // Tell the subclass to refresh the internal bean factory. ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory(); // Prepare the bean factory for use in this context. prepareBeanFactory(beanFactory); try { // Allows post-processing of the bean factory in context subclasses. postProcessBeanFactory(beanFactory); // Invoke factory processors registered as beans in the context. invokeBeanFactoryPostProcessors(beanFactory); // Register bean processors that intercept bean creation. registerBeanPostProcessors(beanFactory); // Initialize message source for this context. initMessageSource(); // Initialize event multicaster for this context. initApplicationEventMulticaster(); // Initialize other special beans in specific context subclasses. onRefresh(); // Check for listener beans and register them. registerListeners(); // Instantiate all remaining (non-lazy-init) singletons. finishBeanFactoryInitialization(beanFactory); // Last step: publish corresponding event. finishRefresh(); } catch (BeansException ex) { if (logger.isWarnEnabled()) { logger.warn("Exception encountered during context initialization - " + "cancelling refresh attempt: " + ex); } // Destroy already created singletons to avoid dangling resources. destroyBeans(); // Reset 'active' flag. cancelRefresh(ex); // Propagate exception to caller. throw ex; } finally { // Reset common introspection caches in Spring's core, since we // might not ever need metadata for singleton beans anymore... resetCommonCaches(); } } }
原因是在初始化异常bean的时候,有其他的bean创建错误。然后没有终止程序。
相关推荐
解析了spring的底层实现机制。public interface BeanFactory { //这里是对FactoryBean的转义定义,因为如果使用bean的名字检索FactoryBean得到的对象是工厂生成的对象, //如果需要得到工厂本身,需要转义 String ...
NoSuchBeanDefinitionException NoSuchMessageException NoSuchRequestHandlingMethodException NotAnAtAspectException NotificationListenerBean NotificationPublisher NotificationPublisherAware ...
SpringMybatis Spring / Mybatis多... org.springframework.beans.factory.NoSuchBeanDefinitionException:没有找到类型为[com.proto.net.aron.aronMapper]的合格Bean作为依赖项:至少应有1个有资格作为此依赖
a road map through nachos,分为 Introduction to Nacho、Nachos Machine、Nachos Threads、User-Level Processes、Nachos Filesystem、Experience With Nachos Assignments、MIPS Architecture等七个部分
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'user' available
catch (NoSuchBeanDefinitionException nex) { ... } catch (BeansException bex) { ... } catch (Exception ex) { ... } } } FlexFactoryImpl 负责实例化 SpringFactoryInstance 并通过 ...
catch (NoSuchBeanDefinitionException nex) { ... } catch (BeansException bex) { ... } catch (Exception ex) { ... } } } FlexFactoryImpl 负责实例化 SpringFactoryInstance 并通过 ...