Java Code Examples for org.springframework.beans.factory.config.BeanFactoryPostProcessor

The following examples show how to use org.springframework.beans.factory.config.BeanFactoryPostProcessor. 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
Source Project: spring-analysis-note   Author: Vip-Augus   File: BeanFactoryPostProcessorBootstrap.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) {
	ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("factory.bean/factory-post-processor.xml");
	BeanFactoryPostProcessor beanFactoryPostProcessor = (BeanFactoryPostProcessor) context.getBean("carPostProcessor");
	beanFactoryPostProcessor.postProcessBeanFactory(context.getBeanFactory());
	// 输出 :Car{maxSpeed=0, brand='*****', price=10000.0},敏感词被替换了
	System.out.println(context.getBean("car"));

	// 硬编码 后处理器执行时间
	BeanFactoryPostProcessor hardCodeBeanFactoryPostProcessor = new HardCodeBeanFactoryPostProcessor();
	context.addBeanFactoryPostProcessor(hardCodeBeanFactoryPostProcessor);
	// 更新上下文
	context.refresh();
	// 输出 :
	// Hard Code BeanFactory Post Processor execute time
	// Car{maxSpeed=0, brand='*****', price=10000.0}
	System.out.println(context.getBean("car"));
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: FactoryBeanTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

	BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
	ppc.postProcessBeanFactory(factory);

	assertNull(factory.getType("betaFactory"));

	Alpha alpha = (Alpha) factory.getBean("alpha");
	Beta beta = (Beta) factory.getBean("beta");
	Gamma gamma = (Gamma) factory.getBean("gamma");
	Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");

	assertSame(beta, alpha.getBeta());
	assertSame(gamma, beta.getGamma());
	assertSame(gamma2, beta.getGamma());
	assertEquals("yourName", beta.getName());
}
 
Example #3
Source Project: java-technology-stack   Author: codeEngraver   File: FactoryBeanTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

	BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
	ppc.postProcessBeanFactory(factory);

	assertNull(factory.getType("betaFactory"));

	Alpha alpha = (Alpha) factory.getBean("alpha");
	Beta beta = (Beta) factory.getBean("beta");
	Gamma gamma = (Gamma) factory.getBean("gamma");
	Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");

	assertSame(beta, alpha.getBeta());
	assertSame(gamma, beta.getGamma());
	assertSame(gamma2, beta.getGamma());
	assertEquals("yourName", beta.getName());
}
 
Example #4
Source Project: saluki   Author: spring-avengers   File: MonitorAutoconfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor(ApplicationContext applicationContext) {
    return new BeanFactoryPostProcessor() {

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
            if (beanFactory instanceof BeanDefinitionRegistry) {
                try {
                    BeanDefinitionRegistry registry = (BeanDefinitionRegistry)beanFactory;
                    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry);
                    scanner.setResourceLoader(applicationContext);
                    scanner.scan("io.github.saluki.monitor.rest");
                } catch (Throwable e) {
                    log.error(e.getMessage(), e);
                }
            }

        }

    };
}
 
Example #5
Source Project: spring4-understanding   Author: langtianya   File: FactoryBeanTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

	BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
	ppc.postProcessBeanFactory(factory);

	assertNull(factory.getType("betaFactory"));

	Alpha alpha = (Alpha) factory.getBean("alpha");
	Beta beta = (Beta) factory.getBean("beta");
	Gamma gamma = (Gamma) factory.getBean("gamma");
	Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");

	assertSame(beta, alpha.getBeta());
	assertSame(gamma, beta.getGamma());
	assertSame(gamma2, beta.getGamma());
	assertEquals("yourName", beta.getName());
}
 
Example #6
Source Project: spring-cloud-stream-binder-kafka   Author: spring-cloud   File: KStreamBinderConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnBean(name = "outerContext")
public static BeanFactoryPostProcessor outerContextBeanFactoryPostProcessor() {
	return beanFactory -> {

		// It is safe to call getBean("outerContext") here, because this bean is
		// registered as first
		// and as independent from the parent context.
		ApplicationContext outerContext = (ApplicationContext) beanFactory
				.getBean("outerContext");
		beanFactory.registerSingleton(
				KafkaStreamsMessageConversionDelegate.class.getSimpleName(),
				outerContext.getBean(KafkaStreamsMessageConversionDelegate.class));
		beanFactory.registerSingleton(
				KafkaStreamsBindingInformationCatalogue.class.getSimpleName(),
				outerContext.getBean(KafkaStreamsBindingInformationCatalogue.class));
		beanFactory.registerSingleton(KeyValueSerdeResolver.class.getSimpleName(),
				outerContext.getBean(KeyValueSerdeResolver.class));
		beanFactory.registerSingleton(
				KafkaStreamsExtendedBindingProperties.class.getSimpleName(),
				outerContext.getBean(KafkaStreamsExtendedBindingProperties.class));
	};
}
 
Example #7
Source Project: flowable-engine   Author: flowable   File: BeansConfigurationHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static AbstractEngineConfiguration parseEngineConfiguration(Resource springResource, String beanName) {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    xmlBeanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    xmlBeanDefinitionReader.loadBeanDefinitions(springResource);

    // Check non singleton beans for types
    // Do not eagerly initialize FactorBeans when getting BeanFactoryPostProcessor beans
    Collection<BeanFactoryPostProcessor> factoryPostProcessors = beanFactory.getBeansOfType(BeanFactoryPostProcessor.class, true, false).values();
    if (factoryPostProcessors.isEmpty()) {
        factoryPostProcessors = Collections.singleton(new PropertyPlaceholderConfigurer());
    }
    for (BeanFactoryPostProcessor factoryPostProcessor : factoryPostProcessors) {
        factoryPostProcessor.postProcessBeanFactory(beanFactory);
    }

    AbstractEngineConfiguration engineConfiguration = (AbstractEngineConfiguration) beanFactory.getBean(beanName);
    engineConfiguration.setBeans(new SpringBeanFactoryProxyMap(beanFactory));
    return engineConfiguration;
}
 
Example #8
Source Project: flowable-engine   Author: flowable   File: BeansConfigurationHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static ProcessEngineConfiguration parseProcessEngineConfiguration(Resource springResource, String beanName) {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
    xmlBeanDefinitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    xmlBeanDefinitionReader.loadBeanDefinitions(springResource);

    // Check non singleton beans for types
    // Do not eagerly initialize FactorBeans when getting BeanFactoryPostProcessor beans
    Collection<BeanFactoryPostProcessor> factoryPostProcessors = beanFactory.getBeansOfType(BeanFactoryPostProcessor.class, true, false).values();
    if (factoryPostProcessors.isEmpty()) {
        factoryPostProcessors = Collections.singleton(new PropertyPlaceholderConfigurer());
    }
    for (BeanFactoryPostProcessor factoryPostProcessor : factoryPostProcessors) {
        factoryPostProcessor.postProcessBeanFactory(beanFactory);
    }

    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) beanFactory.getBean(beanName);
    processEngineConfiguration.setBeans(new SpringBeanFactoryProxyMap(beanFactory));
    return processEngineConfiguration;
}
 
Example #9
Source Project: spring-cloud-function   Author: spring-cloud   File: KotlinLambdaToFunctionAutoConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Will transform all discovered Kotlin's Function lambdas to java
 * Supplier, Function and Consumer, retaining the original Kotlin type
 * characteristics.
 *
 * @return the bean factory post processor
 */
@Bean
public BeanFactoryPostProcessor kotlinToFunctionTransformer() {
	return new BeanFactoryPostProcessor() {

		@Override
		public void postProcessBeanFactory(
				ConfigurableListableBeanFactory beanFactory) throws BeansException {

			String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
			for (String beanDefinitionName : beanDefinitionNames) {
				BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName);

				ResolvableType rt = beanDefinition.getResolvableType();
				if (rt.getType().getTypeName().startsWith("kotlin.jvm.functions.Function")) {
					RootBeanDefinition cbd = new RootBeanDefinition(KotlinFunctionWrapper.class);
					ConstructorArgumentValues ca = new ConstructorArgumentValues();
					ca.addGenericArgumentValue(beanDefinition);
					cbd.setConstructorArgumentValues(ca);
					((BeanDefinitionRegistry) beanFactory).registerBeanDefinition(beanDefinitionName + FunctionRegistration.REGISTRATION_NAME_SUFFIX, cbd);
				}
			}
		}
	};
}
 
Example #10
Source Project: spring-analysis-note   Author: Vip-Augus   File: PostProcessorRegistrationDelegate.java    License: MIT License 5 votes vote down vote up
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
		Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

	for (BeanFactoryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanFactory(beanFactory);
	}
}
 
Example #11
Source Project: spring-analysis-note   Author: Vip-Augus   File: ConfigurationClassProcessingTests.java    License: MIT License 5 votes vote down vote up
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
			BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
			bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
		}
	};
}
 
Example #12
Source Project: spring-analysis-note   Author: Vip-Augus   File: ConfigurationClassAndBFPPTests.java    License: MIT License 5 votes vote down vote up
@Bean
public BeanFactoryPostProcessor bfpp() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
			// no-op
		}
	};
}
 
Example #13
Source Project: spring-analysis-note   Author: Vip-Augus   File: ConfigurationClassAndBFPPTests.java    License: MIT License 5 votes vote down vote up
@Bean
public static final BeanFactoryPostProcessor bfpp() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
			// no-op
		}
	};
}
 
Example #14
Source Project: spring-analysis-note   Author: Vip-Augus   File: FactoryBeanTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

	BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
	ppc.postProcessBeanFactory(factory);

	Beta beta = (Beta) factory.getBean("beta");
	Alpha alpha = (Alpha) factory.getBean("alpha");
	Gamma gamma = (Gamma) factory.getBean("gamma");
	assertSame(beta, alpha.getBeta());
	assertSame(gamma, beta.getGamma());
}
 
Example #15
Source Project: springdoc-openapi   Author: springdoc   File: SpringDocConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Springdoc bean factory post processor bean factory post processor.
 *
 * @return the bean factory post processor
 */
@Bean
@Conditional(CacheOrGroupedOpenApiCondition.class)
@ConditionalOnClass(name = BINDRESULT_CLASS)
@Lazy(false)
static BeanFactoryPostProcessor springdocBeanFactoryPostProcessor() {
	return new SpringdocBeanFactoryConfigurer();
}
 
Example #16
Source Project: springdoc-openapi   Author: springdoc   File: SpringDocConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
	 * Springdoc bean factory post processor 2 bean factory post processor.
	 *
	 * @return the bean factory post processor
	 */
// For spring-boot-1 compatibility
	@Bean
	@Conditional(CacheOrGroupedOpenApiCondition.class)
	@ConditionalOnMissingClass(value = BINDRESULT_CLASS)
	@Lazy(false)
	static BeanFactoryPostProcessor springdocBeanFactoryPostProcessor2() {
		return SpringdocBeanFactoryConfigurer::initBeanFactoryPostProcessor;
	}
 
Example #17
Source Project: java-technology-stack   Author: codeEngraver   File: PostProcessorRegistrationDelegate.java    License: MIT License 5 votes vote down vote up
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
		Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

	for (BeanFactoryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanFactory(beanFactory);
	}
}
 
Example #18
Source Project: java-technology-stack   Author: codeEngraver   File: ConfigurationClassProcessingTests.java    License: MIT License 5 votes vote down vote up
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
			BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
			bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
		}
	};
}
 
Example #19
Source Project: java-technology-stack   Author: codeEngraver   File: ConfigurationClassAndBFPPTests.java    License: MIT License 5 votes vote down vote up
@Bean
public BeanFactoryPostProcessor bfpp() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
			// no-op
		}
	};
}
 
Example #20
Source Project: java-technology-stack   Author: codeEngraver   File: ConfigurationClassAndBFPPTests.java    License: MIT License 5 votes vote down vote up
@Bean
public static final BeanFactoryPostProcessor bfpp() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
			// no-op
		}
	};
}
 
Example #21
Source Project: java-technology-stack   Author: codeEngraver   File: FactoryBeanTests.java    License: MIT License 5 votes vote down vote up
@Test
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);

	BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
	ppc.postProcessBeanFactory(factory);

	Beta beta = (Beta) factory.getBean("beta");
	Alpha alpha = (Alpha) factory.getBean("alpha");
	Gamma gamma = (Gamma) factory.getBean("gamma");
	assertSame(beta, alpha.getBeta());
	assertSame(gamma, beta.getGamma());
}
 
Example #22
Source Project: datawave   Author: NationalSecurityAgency   File: ThreadSafeClassPathXmlApplicationContext.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor) {
    lock.writeLock().lock();
    try {
        configurableApplicationContext.addBeanFactoryPostProcessor(beanFactoryPostProcessor);
    } finally {
        lock.writeLock().unlock();
    }
}
 
Example #23
Source Project: spring-native-query   Author: gasparbarancelli   File: NativeQueryAutoConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
    return bf -> {
        BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) bf;
        String packageScan = PropertyUtil.getValue("native-query.package-scan", "io.github.gasparbarancelli");
        Reflections reflections = new Reflections(packageScan);
        Set<Class<? extends NativeQuery>> nativeQueryList = reflections.getSubTypesOf(NativeQuery.class);
        NativeQueryRegistry nativeQueryRegistry = new NativeQueryRegistryImpl(beanDefinitionRegistry);
        nativeQueryRegistry.registry(nativeQueryList);
    };
}
 
Example #24
Source Project: seed   Author: jadyer   File: JasyptConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * BeanPostProcessorBeanFactoryPostProcessor區別可參考http://www.shouce.ren/api/spring2.5/ch03s07.html<br/>
 * 大致就是BeanFactoryPostProcessor用於Spring註冊BeanDefinition之後,實例化BeanDefinition之前,可修改Bean配置<br/>
 * 比如常見的配置數據庫連接池dataSource,用戶名和密碼放在獨立的一個配置文件中,然後用${jdbc.name}引用裏面的配置
 * </p>
 */
@Bean
public BeanFactoryPostProcessor propertySourcesPostProcessor(){
    PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
    SimpleStringPBEConfig config = new SimpleStringPBEConfig();

    //Master Password used for Encryption/Decryption of properties.
    config.setPassword(this.getProperty(this.environment, "jasypt.encryptor.password", "https://jadyer.cn/"));

    //Encryption/Decryption Algorithm to be used by Jasypt.
    //For more info on how to get available algorithms visit: <a href="http://www.jasypt.org/cli.html"/>Jasypt CLI Tools Page</a>.
    config.setAlgorithm(this.getProperty(this.environment, "jasypt.encryptor.algorithm", "PBEWithMD5AndDES"));

    //Number of hashing iterations to obtain the signing key.
    config.setKeyObtentionIterations(this.getProperty(this.environment, "jasypt.encryptor.keyObtentionIterations", "1000"));

    //The size of the pool of encryptors to be created.
    config.setPoolSize(this.getProperty(this.environment, "jasypt.encryptor.poolSize", "1"));

    //The name of the {@link java.security.Provider} implementation to be used by the encryptor for obtaining the encryption algorithm.
    config.setProviderName(this.getProperty(this.environment, "jasypt.encryptor.providerName", "SunJCE"));

    //A {@link org.jasypt.salt.SaltGenerator} implementation to be used by the encryptor.
    config.setSaltGeneratorClassName(this.getProperty(this.environment, "jasypt.encryptor.saltGeneratorClassname", "org.jasypt.salt.RandomSaltGenerator"));

    //Specify the form in which String output will be encoded. {@code "base64"} or {@code "hexadecimal"}.
    config.setStringOutputType(this.getProperty(this.environment, "jasypt.encryptor.stringOutputType", "hexadecimal"));

    encryptor.setConfig(config);
    return new EnableEncryptablePropertySourcesPostProcessor(encryptor);
}
 
Example #25
Source Project: lams   Author: lamsfoundation   File: PostProcessorRegistrationDelegate.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
		Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

	for (BeanFactoryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanFactory(beanFactory);
	}
}
 
Example #26
Source Project: A.CTable-Frame   Author: sunchenbin   File: ConfigurationUtil.java    License: Apache License 2.0 5 votes vote down vote up
private void initProperties() {
	
	properties = new Properties();
	try {
		String[] postProcessorNames = applicationContext.getBeanNamesForType(BeanFactoryPostProcessor.class, true,
				true);
		for (String ppName : postProcessorNames) {
			BeanFactoryPostProcessor beanProcessor = applicationContext.getBean(ppName,
					BeanFactoryPostProcessor.class);
			if (beanProcessor instanceof PropertyResourceConfigurer) {
				PropertyResourceConfigurer propertyResourceConfigurer = (PropertyResourceConfigurer) beanProcessor;
				Method mergeProperties = PropertiesLoaderSupport.class.getDeclaredMethod("mergeProperties");
				mergeProperties.setAccessible(true);
				Properties props = (Properties) mergeProperties.invoke(propertyResourceConfigurer);

				// get the method convertProperties
				// in class PropertyResourceConfigurer
				Method convertProperties = PropertyResourceConfigurer.class.getDeclaredMethod("convertProperties",
						Properties.class);
				// convert properties
				convertProperties.setAccessible(true);
				convertProperties.invoke(propertyResourceConfigurer, props);

				properties.putAll(props);
			}
		}

	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #27
Source Project: spring-boot-data-geode   Author: spring-projects   File: RegionTemplateAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
BeanFactoryPostProcessor regionTemplateBeanFactoryPostProcessor() {

	return beanFactory -> {

		if (beanFactory instanceof BeanDefinitionRegistry) {

			BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;

			List<String> beanDefinitionNames =
				Arrays.asList(ArrayUtils.nullSafeArray(registry.getBeanDefinitionNames(), String.class));

			Set<String> userRegionTemplateNames = new HashSet<>();

			for (String beanName : beanDefinitionNames) {

				String regionTemplateBeanName = toRegionTemplateBeanName(beanName);

				if (!beanDefinitionNames.contains(regionTemplateBeanName)) {

					BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);

					Class<?> resolvedBeanType = resolveBeanClass(beanDefinition, registry).orElse(null);

					if (isRegionBeanDefinition(resolvedBeanType)) {
						register(newGemfireTemplateBeanDefinition(beanName), regionTemplateBeanName, registry);
					}
					else if (isGemfireTemplateBeanDefinition(resolvedBeanType)) {
						userRegionTemplateNames.add(beanName);
					}
					else if (isBeanWithGemfireTemplateDependency(beanFactory, beanDefinition)) {
						SpringUtils.addDependsOn(beanDefinition, GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);
					}
				}
			}

			setAutoConfiguredRegionTemplateDependencies(registry, userRegionTemplateNames);
		}
	};
}
 
Example #28
Source Project: spring4-understanding   Author: langtianya   File: PostProcessorRegistrationDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Invoke the given BeanFactoryPostProcessor beans.
 */
private static void invokeBeanFactoryPostProcessors(
		Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) {

	for (BeanFactoryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanFactory(beanFactory);
	}
}
 
Example #29
Source Project: spring4-understanding   Author: langtianya   File: ConfigurationClassProcessingTests.java    License: Apache License 2.0 5 votes vote down vote up
public BeanFactoryPostProcessor beanFactoryPostProcessor() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
			BeanDefinition bd = beanFactory.getBeanDefinition("beanPostProcessor");
			bd.getPropertyValues().addPropertyValue("nameSuffix", "-processed-" + myProp);
		}
	};
}
 
Example #30
Source Project: spring4-understanding   Author: langtianya   File: ConfigurationClassAndBFPPTests.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public BeanFactoryPostProcessor bfpp() {
	return new BeanFactoryPostProcessor() {
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
			// no-op
		}
	};
}