@Override public String[] selectImports(AnnotationMetadata metadata) { try { AnnotationAttributes attributes = AnnotationAttributes.fromMap( metadata.getAnnotationAttributes(EnableAutoConfiguration.class.getName(), true)); Assert.notNull( attributes, "No auto-configuration attributes found. Is " + metadata.getClassName() + " annotated with @EnableAutoConfiguration?"); // Find all possible auto configuration classes, filtering duplicates List<String> factories = new ArrayList<String>( new LinkedHashSet<String>( SpringFactoriesLoader.loadFactoryNames( EnableAutoConfiguration.class, this.beanClassLoader))); // Remove those specifically excluded Set<String> excluded = new LinkedHashSet<String>(); excluded.addAll(Arrays.asList(attributes.getStringArray("exclude"))); excluded.addAll(Arrays.asList(attributes.getStringArray("excludeName"))); factories.removeAll(excluded); ConditionEvaluationReport.get(this.beanFactory).recordExclusions(excluded); // Sort factories = new AutoConfigurationSorter(this.resourceLoader).getInPriorityOrder(factories); return factories.toArray(new String[factories.size()]); } catch (IOException ex) { throw new IllegalStateException(ex); } }
/** * Create a new {@link PropertySourceLoader} instance backed by the specified {@link * MutablePropertySources}. * * @param propertySources the destination property sources */ public PropertySourcesLoader(MutablePropertySources propertySources) { Assert.notNull(propertySources, "PropertySources must not be null"); this.propertySources = propertySources; this.loaders = SpringFactoriesLoader.loadFactories( PropertySourceLoader.class, getClass().getClassLoader()); }
private Collection<String> getConfigurationsForAnnotation( Class<?> source, Annotation annotation) { String[] classes = (String[]) AnnotationUtils.getAnnotationAttributes(annotation, true).get("classes"); if (classes.length > 0) { return Arrays.asList(classes); } return SpringFactoriesLoader.loadFactoryNames(source, getClass().getClassLoader()); }
@Test public void importsAreSelected() { configureExclusions(); String[] imports = this.importSelector.selectImports(this.annotationMetadata); assertThat( imports.length, is( equalTo( SpringFactoriesLoader.loadFactoryNames( EnableAutoConfiguration.class, getClass().getClassLoader()) .size()))); assertThat(ConditionEvaluationReport.get(this.beanFactory).getExclusions(), hasSize(0)); }
private List<String> getAutoConfigurationClassNames() { return SpringFactoriesLoader.loadFactoryNames( EnableAutoConfiguration.class, getClass().getClassLoader()); }
@Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { LOGGER.info("Loading Management providers {}", Provider.class.getSimpleName()); Set<String> providers = new HashSet<>( SpringFactoriesLoader.loadFactoryNames( Provider.class, beanFactory.getBeanClassLoader())); LOGGER.info( "\tFound {} {} implementation(s)", providers.size(), Provider.class.getSimpleName()); DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) beanFactory; environment = beanFactory.getBean(Environment.class); List<String> getSecurityProviders = getSecurityProviders(); for (String provider : providers) { try { Class<?> instanceClass = ClassUtils.forName(provider, beanFactory.getBeanClassLoader()); Assert.isAssignable(Provider.class, instanceClass); Provider providerInstance = createInstance((Class<Provider>) instanceClass); if (getSecurityProviders.contains(providerInstance.type())) { LOGGER.info( "Registering a provider {} [{}]", instanceClass.getSimpleName(), providerInstance.type()); if (providerInstance.authenticationManager() != null) { defaultListableBeanFactory.registerBeanDefinition( providerInstance.authenticationManager().getName(), new RootBeanDefinition(providerInstance.authenticationManager().getName())); } if (providerInstance.identityManager() != null) { defaultListableBeanFactory.registerBeanDefinition( providerInstance.identityManager().getName(), new RootBeanDefinition(providerInstance.identityManager().getName())); } Class<?> extension = providerInstance.configuration(); if (extension != null) { LOGGER.info("\tRegistering provider extension: {}", extension.getName()); defaultListableBeanFactory.registerBeanDefinition( extension.getName(), new RootBeanDefinition(extension.getName())); LOGGER.info("\tLoading @Configuration from previous extension {}", extension.getName()); configurationClassPostProcessor.processConfigBeanDefinitions( defaultListableBeanFactory); } } } catch (Exception ex) { LOGGER.error("Unable to instantiate provider: {}", ex); throw new IllegalStateException("Unable to instantiate provider: " + provider, ex); } } }