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() . 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
Source File: TeiidBeanDefinitionPostProcessor.java    From teiid-spring-boot with Apache License 2.0 6 votes vote down vote up
@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 File: StatefulFactory.java    From statefulj with 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
Source File: FeignBeanFactoryPostProcessor.java    From spring-cloud-learning with MIT License 5 votes vote down vote up
/**
 * @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
Source File: FeignBeanFactoryPostProcessor.java    From SpringCloud-Shop with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (containsBeanDefinition(beanFactory, "feignContext", "eurekaAutoServiceRegistration")) {
        BeanDefinition bd = beanFactory.getBeanDefinition("feignContext");
        bd.setDependsOn("eurekaAutoServiceRegistration");
    }
}
 
Example 5
Source File: BeanDependencyManager.java    From jetcache with 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
Source File: MongoDbFactoryDependsOnPostProcessor.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
    for (String beanName : getMongoDbFactoryBeanNames(beanFactory)) {
        BeanDefinition definition = getBeanDefinition(beanName, beanFactory);
        definition.setDependsOn(StringUtils.addStringToArray(
                definition.getDependsOn(), this.dependsOn));
    }

}