/** * 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 a Map with bean name as key and Lifecycle instance as value * @param beanName the name of the bean to start */ private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) { Lifecycle bean = lifecycleBeans.remove(beanName); if (bean != null && bean != this) { String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName); for (String dependency : dependenciesForBean) { doStart(lifecycleBeans, dependency, autoStartupOnly); } if (!bean.isRunning() && (!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) { if (logger.isTraceEnabled()) { logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]"); } try { bean.start(); } catch (Throwable ex) { throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex); } if (logger.isDebugEnabled()) { logger.debug("Successfully started bean '" + beanName + "'"); } } } }
appendArray(result, bf.getDependenciesForBean(beanName)); result.append("\n}"); elementAppended = true;
appendArray(result, bf.getDependenciesForBean(beanName)); result.append("\n}"); elementAppended = true;
/** * 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 a Map with bean name as key and Lifecycle instance as value * @param beanName the name of the bean to start */ private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) { Lifecycle bean = lifecycleBeans.remove(beanName); if (bean != null && bean != this) { String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName); for (String dependency : dependenciesForBean) { doStart(lifecycleBeans, dependency, autoStartupOnly); } if (!bean.isRunning() && (!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) { if (logger.isTraceEnabled()) { logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]"); } try { bean.start(); } catch (Throwable ex) { throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex); } if (logger.isDebugEnabled()) { logger.debug("Successfully started bean '" + beanName + "'"); } } } }
public Map<String, Object> getDependencies(String key) { if (!readOnly) { Map<String, Object> dependents = new HashMap<>(); for (String dependentKey : ((ConfigurableApplicationContext) applicationContext).getBeanFactory() .getDependenciesForBean(key)) { boolean isBeanDefinition = ((ConfigurableApplicationContext) applicationContext).getBeanFactory().containsBeanDefinition(dependentKey); if (isBeanDefinition && applicationContext.isSingleton(dependentKey)) { dependents.put(dependentKey, get(dependentKey)); } } return dependents; } throw new UnsupportedOperationException("This operation is only available when this registry is backed by a ConfigurableApplicationContext"); }
private static BeanDescriptor describeBean(String name, BeanDefinition definition, ConfigurableListableBeanFactory factory) { return new BeanDescriptor(factory.getAliases(name), definition.getScope(), factory.getType(name), definition.getResourceDescription(), factory.getDependenciesForBean(name)); }
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml"); ConfigurableListableBeanFactory bf = ctx.getBeanFactory(); bf.getDependenciesForBean(beanName)
public Map<String, Object> getDependencies(String key) { if (!readOnly) { Map<String, Object> dependents = new HashMap<>(); for (String dependentKey : ((ConfigurableApplicationContext) applicationContext).getBeanFactory() .getDependenciesForBean(key)) { boolean isBeanDefinition = ((ConfigurableApplicationContext) applicationContext).getBeanFactory().containsBeanDefinition(dependentKey); if (isBeanDefinition && applicationContext.isSingleton(dependentKey)) { dependents.put(dependentKey, get(dependentKey)); } } return dependents; } throw new UnsupportedOperationException("This operation is only available when this registry is backed by a ConfigurableApplicationContext"); }
protected Map<String, Object> getDependencies(String key) { if (!readOnly) { Map<String, Object> dependents = new HashMap<>(); for (String dependentKey : ((ConfigurableApplicationContext) applicationContext).getBeanFactory().getDependenciesForBean(key)) { boolean isBeanDefinition = ((ConfigurableApplicationContext) applicationContext).getBeanFactory().containsBeanDefinition(dependentKey); if (isBeanDefinition && applicationContext.isSingleton(dependentKey)) { dependents.put(dependentKey, get(dependentKey)); } } return dependents; } throw new UnsupportedOperationException("This operation is only available when this registry is backed by a ConfigurableApplicationContext"); }
appendArray(result, bf.getDependenciesForBean(beanName)); result.append("\n}"); elementAppended = true;
/** * 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 a Map with bean name as key and Lifecycle instance as value * @param beanName the name of the bean to start */ private void doStart(Map<String, ? extends Lifecycle> lifecycleBeans, String beanName, boolean autoStartupOnly) { Lifecycle bean = lifecycleBeans.remove(beanName); if (bean != null && bean != this) { String[] dependenciesForBean = getBeanFactory().getDependenciesForBean(beanName); for (String dependency : dependenciesForBean) { doStart(lifecycleBeans, dependency, autoStartupOnly); } if (!bean.isRunning() && (!autoStartupOnly || !(bean instanceof SmartLifecycle) || ((SmartLifecycle) bean).isAutoStartup())) { if (logger.isTraceEnabled()) { logger.trace("Starting bean '" + beanName + "' of type [" + bean.getClass().getName() + "]"); } try { bean.start(); } catch (Throwable ex) { throw new ApplicationContextException("Failed to start bean '" + beanName + "'", ex); } if (logger.isDebugEnabled()) { logger.debug("Successfully started bean '" + beanName + "'"); } } } }
private static void getTransitiveBeans(ConfigurableListableBeanFactory beanFactory, String beanName, boolean rawFactoryBeans, Set<String> beanNames, Set<String> innerBeans) { String transformedBeanName = org.springframework.beans.factory.BeanFactoryUtils.transformedBeanName(beanName); // strip out '&' just in case String[] beans = beanFactory.getDependenciesForBean(transformedBeanName); for (int i = 0; i < beans.length; i++) { String bean = beans[i]; // top-level beans if (beanFactory.containsBean(bean)) { // & if needed if (rawFactoryBeans && beanFactory.isFactoryBean(bean)) bean = BeanFactory.FACTORY_BEAN_PREFIX + beans[i]; if (!beanNames.contains(bean)) { beanNames.add(bean); getTransitiveBeans(beanFactory, bean, rawFactoryBeans, beanNames, innerBeans); } } // nested-beans are discarded from the main list but are tracked for dependencies to // top-level beans else { if (innerBeans.add(bean)) { getTransitiveBeans(beanFactory, bean, rawFactoryBeans, beanNames, innerBeans); } } } } }