@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); } }; }
/** * Invoke the given BeanDefinitionRegistryPostProcessor beans. */ private static void invokeBeanDefinitionRegistryPostProcessors( Collection<? extends BeanDefinitionRegistryPostProcessor> postProcessors, BeanDefinitionRegistry registry) { for (BeanDefinitionRegistryPostProcessor postProcessor : postProcessors) { postProcessor.postProcessBeanDefinitionRegistry(registry); } }
@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); }); } }; }
/** * @param dependsOn * the dependsOn to set */ public void setDependsOn(final List<BeanDefinitionRegistryPostProcessor> dependsOn) { this.dependsOn = dependsOn; }