日期:2014-05-20 浏览次数:20722 次
//--------------------------------- // Implementation of Lifecycle interface //--------------------------------- public void start() { Map lifecycleBeans = getLifecycleBeans(); for (Iterator it = new LinkedHashSet(lifecycleBeans.keySet()).iterator(); it.hasNext();) { String beanName = (String) it.next(); doStart(lifecycleBeans, beanName); } publishEvent(new ContextStartedEvent(this)); } /** * Start the specified bean as part of the given set of Lifecycle beans, * making sure that any beans that it depends on are started first. * @param lifecycleBeans Map with bean name as key and Lifecycle instance as value * @param beanName the name of the bean to start */ private void doStart(Map lifecycleBeans, String beanName) { Lifecycle bean = (Lifecycle) lifecycleBeans.get(beanName); if (bean != null) { String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName); for (int i = 0; i < dependenciesForBean.length; i++) { doStart(lifecycleBeans, dependenciesForBean[i]); } if (!bean.isRunning()) { bean.start(); } lifecycleBeans.remove(beanName); } } 注意里面有一个递归。。开始生命周期。。
------解决方案--------------------
主要就是一个bean的加载过程,完成bean对象的初始化工作