Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor

The following examples show how to use org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor. 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
@Bean
public BeanDefinitionRegistryPostProcessor postProcessor(ConfigurableEnvironment environment) {
    return new BeanDefinitionRegistryPostProcessor() {
        @Override
        public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
            MutablePropertySources propertySources = environment.getPropertySources();
            Map<String, Object> source = new HashMap<>();
            source.put("enabled", "true");
            propertySources.addFirst(new MapPropertySource("for @ConditionalOnProperty", source));
        }

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        }
    };
}
 
Example 2
Source Project: spring-cloud-function   Source File: SingletonTests.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public static BeanDefinitionRegistryPostProcessor processor() {
	return new BeanDefinitionRegistryPostProcessor() {

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

		@Override
		public void postProcessBeanDefinitionRegistry(
				BeanDefinitionRegistry registry) throws BeansException {
			// Simulates what happens when you add a compiled function
			RootBeanDefinition beanDefinition = new RootBeanDefinition(
					MySupplier.class);
			registry.registerBeanDefinition("words", beanDefinition);
		}
	};
}
 
Example 3
Source Project: spring-cloud-function   Source File: SingletonTests.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public static BeanDefinitionRegistryPostProcessor processor() {
	return new BeanDefinitionRegistryPostProcessor() {

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

		@Override
		public void postProcessBeanDefinitionRegistry(
				BeanDefinitionRegistry registry) throws BeansException {
			// Simulates what happens when you add a compiled function
			RootBeanDefinition beanDefinition = new RootBeanDefinition(
					MySupplier.class);
			registry.registerBeanDefinition("words", beanDefinition);
		}
	};
}
 
Example 4
/**
 * Invoke the given BeanDefinitionRegistryPostProcessor beans.
 */
private static void invokeBeanDefinitionRegistryPostProcessors(
		Collection<? extends BeanDefinitionRegistryPostProcessor> postProcessors, BeanDefinitionRegistry registry) {

	for (BeanDefinitionRegistryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanDefinitionRegistry(registry);
	}
}
 
Example 5
@Bean
public static BeanDefinitionRegistryPostProcessor bdrpp() {
	return new BeanDefinitionRegistryPostProcessor() {
		@Override
		public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
			registry.registerBeanDefinition("myTestBean", new RootBeanDefinition(TestBean.class));
		}
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
		}
	};
}
 
Example 6
/**
 * Invoke the given BeanDefinitionRegistryPostProcessor beans.
 */
private static void invokeBeanDefinitionRegistryPostProcessors(
		Collection<? extends BeanDefinitionRegistryPostProcessor> postProcessors, BeanDefinitionRegistry registry) {

	for (BeanDefinitionRegistryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanDefinitionRegistry(registry);
	}
}
 
Example 7
@Bean
public static BeanDefinitionRegistryPostProcessor bdrpp() {
	return new BeanDefinitionRegistryPostProcessor() {
		@Override
		public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
			registry.registerBeanDefinition("myTestBean", new RootBeanDefinition(TestBean.class));
		}
		@Override
		public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
		}
	};
}
 
Example 8
/**
 * Invoke the given BeanDefinitionRegistryPostProcessor beans.
 */
private static void invokeBeanDefinitionRegistryPostProcessors(
		Collection<? extends BeanDefinitionRegistryPostProcessor> postProcessors, BeanDefinitionRegistry registry) {

	for (BeanDefinitionRegistryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanDefinitionRegistry(registry);
	}
}
 
Example 9
/**
 * Invoke the given BeanDefinitionRegistryPostProcessor beans.
 */
private static void invokeBeanDefinitionRegistryPostProcessors(
		Collection<? extends BeanDefinitionRegistryPostProcessor> postProcessors, BeanDefinitionRegistry registry) {

	for (BeanDefinitionRegistryPostProcessor postProcessor : postProcessors) {
		postProcessor.postProcessBeanDefinitionRegistry(registry);
	}
}
 
Example 10
@Bean
public static BeanDefinitionRegistryPostProcessor removeUnwantedAutomaticFilterRegistration() {
    return new BeanDefinitionRegistryPostProcessor() {
        @Override
        public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        }

        @Override
        public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) throws BeansException {
            DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) bf;
            Set<String> filtersToDisable = ImmutableSet.of("samlEntryPoint", "samlFilter", "samlIDPDiscovery", "metadataDisplayFilter",
                    "samlWebSSOHoKProcessingFilter", "samlWebSSOProcessingFilter",
                    "samlLogoutProcessingFilter", "samlLogoutFilter", "metadataGeneratorFilter");
            Arrays.stream(beanFactory.getBeanNamesForType(javax.servlet.Filter.class))
                    .filter(filtersToDisable::contains)
                    .forEach(name -> {
                        BeanDefinition definition = BeanDefinitionBuilder
                                .genericBeanDefinition(FilterRegistrationBean.class)
                                .setScope(BeanDefinition.SCOPE_SINGLETON)
                                .addConstructorArgReference(name)
                                .addConstructorArgValue(new ServletRegistrationBean[]{})
                                .addPropertyValue("enabled", false)
                                .getBeanDefinition();
                        beanFactory.registerBeanDefinition(name + "FilterRegistrationBean", definition);
                    });
        }
    };
}
 
Example 11
@Bean
public BeanDefinitionRegistryPostProcessor velocityToolsBeanDefinitionRegistryPostProcessor(
        VelocityToolsRepository velocityToolsRepository) {
    return new VelocityToolsBeanDefinitionRegistryPostProcessor(velocityToolsRepository);
}