Java Code Examples for org.springframework.beans.factory.config.BeanDefinition#setDependsOn()

The following examples show how to use org.springframework.beans.factory.config.BeanDefinition#setDependsOn() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    ArrayList<String> datasources = new ArrayList<String>();
    BeanDefinition datasourceBeanDefinition = registry.getBeanDefinition("dataSource");
    for (String beanName : registry.getBeanDefinitionNames()) {
        if (beanName.startsWith("org.springframework") || beanName.contentEquals("dataSource")) {
            continue;
        }
        final BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
        if (isMatch(beanDefinition, beanName)) {
            datasources.add(beanName);
        }
    }
    logger.info("Found data sources: " + datasources);
    datasourceBeanDefinition.setDependsOn(datasources.toArray(new String[datasources.size()]));
}
 
Example 2
Source Project: statefulj   File: StatefulFactory.java    License: Apache License 2.0 6 votes vote down vote up
private String registerStatefulFSMBean(
		ReferenceFactory referenceFactory,
		Class<?> statefulClass,
		String fsmBeanId,
		String factoryId,
		List<String> transitionIds,
		BeanDefinitionRegistry reg) {
	String statefulFSMBeanId = referenceFactory.getStatefulFSMId();
	BeanDefinition statefulFSMBean = BeanDefinitionBuilder
			.genericBeanDefinition(StatefulFSMImpl.class)
			.getBeanDefinition();
	ConstructorArgumentValues args = statefulFSMBean.getConstructorArgumentValues();
	args.addIndexedArgumentValue(0, new RuntimeBeanReference(fsmBeanId));
	args.addIndexedArgumentValue(1, statefulClass);
	args.addIndexedArgumentValue(2, new RuntimeBeanReference(factoryId));
	reg.registerBeanDefinition(statefulFSMBeanId, statefulFSMBean);
	statefulFSMBean.setDependsOn(transitionIds.toArray(new String[]{}));
	return statefulFSMBeanId;
}
 
Example 3
/**
 * @param beanFactory bean工厂
 * @throws BeansException
 */
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
        BeanDefinition definition = beanFactory.getBeanDefinition("feignContext");
        definition.setDependsOn("eurekaAutoServiceRegistration");
    }
}
 
Example 4
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
        BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
        bd.setDependsOn("eurekaAutoServiceRegistration");
    }
}
 
Example 5
Source Project: jetcache   File: BeanDependencyManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String[] autoInitBeanNames = beanFactory.getBeanNamesForType(AbstractCacheAutoInit.class, false, false);
    if (autoInitBeanNames != null) {
        BeanDefinition bd = beanFactory.getBeanDefinition(JetCacheAutoConfiguration.GLOBAL_CACHE_CONFIG_NAME);
        String[] dependsOn = bd.getDependsOn();
        if (dependsOn == null) {
            dependsOn = new String[0];
        }
        int oldLen = dependsOn.length;
        dependsOn = Arrays.copyOf(dependsOn, dependsOn.length + autoInitBeanNames.length);
        System.arraycopy(autoInitBeanNames,0, dependsOn, oldLen, autoInitBeanNames.length);
        bd.setDependsOn(dependsOn);
    }
}
 
Example 6
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    for (String beanName : getMongoDbFactoryBeanNames(beanFactory)) {
        BeanDefinition definition = getBeanDefinition(beanName, beanFactory);
        definition.setDependsOn(StringUtils.addStringToArray(
                definition.getDependsOn(), this.dependsOn));
    }

}