use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class PropertyMappingContextCustomizerFactoryTests method getContextCustomizerWhenHasNoMappingShouldNotAddPropertySource.
@Test
void getContextCustomizerWhenHasNoMappingShouldNotAddPropertySource() {
ContextCustomizer customizer = this.factory.createContextCustomizer(NoMapping.class, null);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
ConfigurableListableBeanFactory beanFactory = mock(ConfigurableListableBeanFactory.class);
given(context.getEnvironment()).willReturn(environment);
given(context.getBeanFactory()).willReturn(beanFactory);
customizer.customizeContext(context, null);
then(environment).shouldHaveNoInteractions();
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project dubbo by alibaba.
the class DubboConfigBeanDefinitionConflictApplicationListener method resolveUniqueApplicationConfigBean.
/**
* Resolve the unique {@link ApplicationConfig} Bean
* @param registry {@link BeanDefinitionRegistry} instance
* @param beanFactory {@link ConfigurableListableBeanFactory} instance
* @see EnableDubboConfig
*/
private void resolveUniqueApplicationConfigBean(BeanDefinitionRegistry registry, ListableBeanFactory beanFactory) {
String[] beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
if (beansNames.length < 2) {
// If the number of ApplicationConfig beans is less than two, return immediately.
return;
}
Environment environment = beanFactory.getBean(ENVIRONMENT_BEAN_NAME, Environment.class);
// Remove ApplicationConfig Beans that are configured by "dubbo.application.*"
Stream.of(beansNames).filter(beansName -> isConfiguredApplicationConfigBeanName(environment, beansName)).forEach(registry::removeBeanDefinition);
beansNames = beanNamesForTypeIncludingAncestors(beanFactory, ApplicationConfig.class);
if (beansNames.length > 1) {
throw new IllegalStateException(String.format("There are more than one instances of %s, whose bean definitions : %s", ApplicationConfig.class.getSimpleName(), Stream.of(beansNames).map(registry::getBeanDefinition).collect(Collectors.toList())));
}
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project dubbo by alibaba.
the class DubboConfigEarlyInitializationTest method testDubboConfigEarlyInitializationPostProcessor.
@Test
public void testDubboConfigEarlyInitializationPostProcessor() {
assertTrue(applicationContext instanceof GenericApplicationContext);
ConfigurableListableBeanFactory clBeanFactory = ((GenericApplicationContext) applicationContext).getBeanFactory();
assertTrue(clBeanFactory instanceof DefaultListableBeanFactory);
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) clBeanFactory;
List<BeanPostProcessor> beanPostProcessorList = beanFactory.getBeanPostProcessors();
assertEquals(beanFactory.getBeanPostProcessorCount(), beanPostProcessorList.size());
boolean containsDubboConfigEarlyInitializationPostProcessor = false;
for (BeanPostProcessor beanPostProcessor : beanPostProcessorList) {
if (beanPostProcessor instanceof DubboConfigEarlyRegistrationPostProcessor.DubboConfigEarlyInitializationPostProcessor) {
containsDubboConfigEarlyInitializationPostProcessor = true;
break;
}
}
assertTrue(containsDubboConfigEarlyInitializationPostProcessor);
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project engine by craftercms.
the class BeanDefinitionUtils method createBeanDefinitionFromOriginal.
/**
* Creates a bean definition for the specified bean name. If the parent context of the current context contains a
* bean definition with the same name, the definition is created as a bean copy of the parent definition. This
* method is useful for config parsers that want to create a bean definition from configuration but also want to
* retain the default properties of the original bean.
*
* @param applicationContext the current application context
* @param beanName
* @return the bean definition
*/
public static BeanDefinition createBeanDefinitionFromOriginal(ApplicationContext applicationContext, String beanName) {
ApplicationContext parentContext = applicationContext.getParent();
BeanDefinition parentDefinition = null;
if (parentContext != null && parentContext.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory) {
ConfigurableListableBeanFactory parentBeanFactory = (ConfigurableListableBeanFactory) parentContext.getAutowireCapableBeanFactory();
try {
parentDefinition = parentBeanFactory.getBeanDefinition(beanName);
} catch (NoSuchBeanDefinitionException e) {
}
}
if (parentDefinition != null) {
return new GenericBeanDefinition(parentDefinition);
} else {
return new GenericBeanDefinition();
}
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project grails-core by grails.
the class DefaultGrailsPlugin method invokeOnChangeListener.
private void invokeOnChangeListener(Map event) {
onChangeListener.setDelegate(this);
onChangeListener.call(new Object[] { event });
if (!(applicationContext instanceof GenericApplicationContext)) {
return;
}
// Apply any factory post processors in case the change listener has changed any
// bean definitions (GRAILS-5763)
GenericApplicationContext ctx = (GenericApplicationContext) applicationContext;
ConfigurableListableBeanFactory beanFactory = ctx.getBeanFactory();
for (BeanFactoryPostProcessor postProcessor : ctx.getBeanFactoryPostProcessors()) {
try {
postProcessor.postProcessBeanFactory(beanFactory);
} catch (IllegalStateException e) {
// post processor doesn't allow running again, just continue
}
}
}
Aggregations