use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project grails-core by grails.
the class AbstractGrailsPluginManager method doRuntimeConfiguration.
/**
* Base implementation that simply goes through the list of plugins and calls doWithRuntimeConfiguration on each
* @param springConfig The RuntimeSpringConfiguration instance
*/
public void doRuntimeConfiguration(RuntimeSpringConfiguration springConfig) {
ApplicationContext context = springConfig.getUnrefreshedApplicationContext();
AutowireCapableBeanFactory autowireCapableBeanFactory = context.getAutowireCapableBeanFactory();
if (autowireCapableBeanFactory instanceof ConfigurableListableBeanFactory) {
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) autowireCapableBeanFactory;
ConversionService existingConversionService = beanFactory.getConversionService();
ConverterRegistry converterRegistry;
if (existingConversionService == null) {
GenericConversionService conversionService = new GenericConversionService();
converterRegistry = conversionService;
beanFactory.setConversionService(conversionService);
} else {
converterRegistry = (ConverterRegistry) existingConversionService;
}
converterRegistry.addConverter(new Converter<NavigableMap.NullSafeNavigator, Object>() {
@Override
public Object convert(NavigableMap.NullSafeNavigator source) {
return null;
}
});
}
checkInitialised();
for (GrailsPlugin plugin : pluginList) {
if (plugin.supportsCurrentScopeAndEnvironment() && plugin.isEnabled(context.getEnvironment().getActiveProfiles())) {
plugin.doWithRuntimeConfiguration(springConfig);
}
}
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-cloud-connectors by spring-cloud.
the class AbstractCloudServiceConnectorFactory method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) getBeanFactory();
if (cloud == null) {
if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
}
CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
cloud = cloudFactory.getCloud();
}
if (!StringUtils.hasText(serviceId)) {
List<? extends ServiceInfo> infos = cloud.getServiceInfos(serviceConnectorType);
if (infos.size() != 1) {
throw new CloudException("Expected 1 service matching " + serviceConnectorType.getName() + " type, but found " + infos.size());
}
serviceId = infos.get(0).getId();
}
super.afterPropertiesSet();
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-cloud-connectors by spring-cloud.
the class CloudScanHelper method initializeCloud.
private void initializeCloud(BeanDefinitionRegistry registry) {
if (cloud != null) {
return;
}
ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) registry;
if (beanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
beanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
}
CloudFactory cloudFactory = beanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
cloud = cloudFactory.getCloud();
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class OnBeanCondition method getMatchingBeans.
protected final MatchResult getMatchingBeans(ConditionContext context, Spec<?> spec) {
ClassLoader classLoader = context.getClassLoader();
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
boolean considerHierarchy = spec.getStrategy() != SearchStrategy.CURRENT;
Set<Class<?>> parameterizedContainers = spec.getParameterizedContainers();
if (spec.getStrategy() == SearchStrategy.ANCESTORS) {
BeanFactory parent = beanFactory.getParentBeanFactory();
Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent, "Unable to use SearchStrategy.ANCESTORS");
beanFactory = (ConfigurableListableBeanFactory) parent;
}
MatchResult result = new MatchResult();
Set<String> beansIgnoredByType = getNamesOfBeansIgnoredByType(classLoader, beanFactory, considerHierarchy, spec.getIgnoredTypes(), parameterizedContainers);
for (String type : spec.getTypes()) {
Collection<String> typeMatches = getBeanNamesForType(classLoader, considerHierarchy, beanFactory, type, parameterizedContainers);
Iterator<String> iterator = typeMatches.iterator();
while (iterator.hasNext()) {
String match = iterator.next();
if (beansIgnoredByType.contains(match) || ScopedProxyUtils.isScopedTarget(match)) {
iterator.remove();
}
}
if (typeMatches.isEmpty()) {
result.recordUnmatchedType(type);
} else {
result.recordMatchedType(type, typeMatches);
}
}
for (String annotation : spec.getAnnotations()) {
Set<String> annotationMatches = getBeanNamesForAnnotation(classLoader, beanFactory, annotation, considerHierarchy);
annotationMatches.removeAll(beansIgnoredByType);
if (annotationMatches.isEmpty()) {
result.recordUnmatchedAnnotation(annotation);
} else {
result.recordMatchedAnnotation(annotation, annotationMatches);
}
}
for (String beanName : spec.getNames()) {
if (!beansIgnoredByType.contains(beanName) && containsBean(beanFactory, beanName, considerHierarchy)) {
result.recordMatchedName(beanName);
} else {
result.recordUnmatchedName(beanName);
}
}
return result;
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class OnExpressionCondition method getMatchOutcome.
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
String expression = (String) metadata.getAnnotationAttributes(ConditionalOnExpression.class.getName()).get("value");
expression = wrapIfNecessary(expression);
ConditionMessage.Builder messageBuilder = ConditionMessage.forCondition(ConditionalOnExpression.class, "(" + expression + ")");
expression = context.getEnvironment().resolvePlaceholders(expression);
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
if (beanFactory != null) {
boolean result = evaluateExpression(beanFactory, expression);
return new ConditionOutcome(result, messageBuilder.resultedIn(result));
}
return ConditionOutcome.noMatch(messageBuilder.because("no BeanFactory available."));
}
Aggregations