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

The following examples show how to use org.springframework.beans.factory.config.BeanFactoryPostProcessor. 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: BeansConfigurationHelper.java    From flowable-engine with 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 #2
Source File: BeansConfigurationHelper.java    From flowable-engine with 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 #3
Source File: MonitorAutoconfiguration.java    From saluki with 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 #4
Source File: FactoryBeanTests.java    From spring4-understanding with 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 #5
Source File: KotlinLambdaToFunctionAutoConfiguration.java    From spring-cloud-function with 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 #6
Source File: KStreamBinderConfiguration.java    From spring-cloud-stream-binder-kafka with 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 File: FactoryBeanTests.java    From java-technology-stack with 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 #8
Source File: BeanFactoryPostProcessorBootstrap.java    From spring-analysis-note with 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 #9
Source File: FactoryBeanTests.java    From spring-analysis-note with 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 #10
Source File: FactoryBeanTests.java    From java-technology-stack with 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 #11
Source File: NativeQueryAutoConfiguration.java    From spring-native-query with 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 #12
Source File: ThreadSafeClassPathXmlApplicationContext.java    From datawave with 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 #13
Source File: ConfigurationClassProcessingTests.java    From spring-analysis-note with 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 #14
Source File: ConfigurationClassAndBFPPTests.java    From spring-analysis-note with 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 #15
Source File: SpringDocConfiguration.java    From springdoc-openapi with 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 #16
Source File: SpringDocConfiguration.java    From springdoc-openapi with 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 #17
Source File: SakaiApplicationContext.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
 * Add bean-created post processors.
 * @param beanFactory
 */
public void invokePostProcessorCreators(ConfigurableListableBeanFactory beanFactory) {
	String[] postProcessorCreatorNames = beanFactory.getBeanNamesForType(BeanFactoryPostProcessorCreator.class, false, false);
	for (int i = 0; i < postProcessorCreatorNames.length; i++) {
		BeanFactoryPostProcessorCreator postProcessorCreator = (BeanFactoryPostProcessorCreator)beanFactory.getBean(postProcessorCreatorNames[i]);
		for (BeanFactoryPostProcessor beanFactoryPostProcessor : postProcessorCreator.getBeanFactoryPostProcessors()) {
			addBeanFactoryPostProcessor(beanFactoryPostProcessor);
		}
	}
}
 
Example #18
Source File: FactoryBeanTests.java    From spring-analysis-note with 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 #19
Source File: ConfigurationClassAndBFPPTests.java    From java-technology-stack with 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 #20
Source File: JasyptConfiguration.java    From seed with 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 #21
Source File: GlobalKTableBinderConfiguration.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 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(
				KafkaStreamsExtendedBindingProperties.class.getSimpleName(),
				outerContext.getBean(KafkaStreamsExtendedBindingProperties.class));
	};
}
 
Example #22
Source File: KTableBinderConfiguration.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 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(
				KafkaStreamsExtendedBindingProperties.class.getSimpleName(),
				outerContext.getBean(KafkaStreamsExtendedBindingProperties.class));
	};
}
 
Example #23
Source File: PostProcessorRegistrationDelegate.java    From lams with 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 #24
Source File: FactoryBeanTests.java    From spring4-understanding with Apache License 2.0 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 #25
Source File: ConfigurationUtil.java    From A.CTable-Frame with 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 #26
Source File: RegionTemplateAutoConfiguration.java    From spring-boot-data-geode with 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 #27
Source File: ConfigurationClassAndBFPPTests.java    From spring4-understanding with Apache License 2.0 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 #28
Source File: ConfigurationClassAndBFPPTests.java    From spring4-understanding with 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
		}
	};
}
 
Example #29
Source File: PostProcessorRegistrationDelegate.java    From spring4-understanding with 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 #30
Source File: ConfigurationClassProcessingTests.java    From spring4-understanding with 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);
		}
	};
}