Example usage for org.springframework.core.io.support SpringFactoriesLoader loadFactories

List of usage examples for org.springframework.core.io.support SpringFactoriesLoader loadFactories

Introduction

In this page you can find the example usage for org.springframework.core.io.support SpringFactoriesLoader loadFactories.

Prototype

public static <T> List<T> loadFactories(Class<T> factoryType, @Nullable ClassLoader classLoader) 

Source Link

Document

Load and instantiate the factory implementations of the given type from #FACTORIES_RESOURCE_LOCATION , using the given class loader.

Usage

From source file:io.syndesis.credential.CredentialProviderRegistry.java

CredentialProviderRegistry(final DataManager dataManager) {
    this.dataManager = dataManager;

    credentialProviderFactories = SpringFactoriesLoader
            .loadFactories(CredentialProviderFactory.class, ClassUtils.getDefaultClassLoader()).stream()
            .collect(Collectors.toMap(CredentialProviderFactory::id, Function.identity()));
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java

protected List<AutoConfigurationImportFilter> getAutoConfigurationImportFilters() {
    return SpringFactoriesLoader.loadFactories(AutoConfigurationImportFilter.class, this.beanClassLoader);
}

From source file:org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.java

protected List<AutoConfigurationImportListener> getAutoConfigurationImportListeners() {
    return SpringFactoriesLoader.loadFactories(AutoConfigurationImportListener.class, this.beanClassLoader);
}

From source file:org.springframework.boot.context.config.ConfigFileApplicationListener.java

private void onApplicationEnvironmentPreparedEvent(ApplicationEnvironmentPreparedEvent event) {
    List<EnvironmentPostProcessor> postProcessors = SpringFactoriesLoader
            .loadFactories(EnvironmentPostProcessor.class, getClass().getClassLoader());
    postProcessors.add(this);
    for (EnvironmentPostProcessor postProcessor : postProcessors) {
        postProcessor.postProcessEnvironment(event.getEnvironment(), event.getSpringApplication());
    }/*  ww  w . j  a v a2s. co m*/
}

From source file:org.springframework.boot.diagnostics.FailureAnalyzers.java

private boolean report(FailureAnalysis analysis, ClassLoader classLoader) {
    List<FailureAnalysisReporter> reporters = SpringFactoriesLoader.loadFactories(FailureAnalysisReporter.class,
            classLoader);/*from   w w  w .  jav a2  s .  c  o m*/
    if (analysis == null || reporters.isEmpty()) {
        return false;
    }
    for (FailureAnalysisReporter reporter : reporters) {
        reporter.report(analysis);
    }
    return true;
}

From source file:org.springframework.boot.env.PropertySourcesLoader.java

/**
 * Create a new {@link PropertySourceLoader} instance backed by the specified
 * {@link MutablePropertySources}./*w  w  w. ja v  a2s.c o  m*/
 * @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());
}

From source file:org.springframework.boot.loader.tools.Repackager.java

private LayoutFactory getLayoutFactory() {
    if (this.layoutFactory != null) {
        return this.layoutFactory;
    }//from w w  w .jav  a2  s .  c  o m
    List<LayoutFactory> factories = SpringFactoriesLoader.loadFactories(LayoutFactory.class, null);
    if (factories.isEmpty()) {
        return new DefaultLayoutFactory();
    }
    Assert.state(factories.size() == 1, "No unique LayoutFactory found");
    return factories.get(0);
}

From source file:org.springframework.boot.test.context.SpringBootTestContextBootstrapper.java

@Override
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() {
    Set<Class<? extends TestExecutionListener>> listeners = super.getDefaultTestExecutionListenerClasses();
    List<DefaultTestExecutionListenersPostProcessor> postProcessors = SpringFactoriesLoader
            .loadFactories(DefaultTestExecutionListenersPostProcessor.class, getClass().getClassLoader());
    for (DefaultTestExecutionListenersPostProcessor postProcessor : postProcessors) {
        listeners = postProcessor.postProcessDefaultTestExecutionListeners(listeners);
    }//from  ww w  . j a va  2  s  .c o  m
    return listeners;
}

From source file:org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.java

/**
 * Creates the {@link HttpSecurity} or returns the current instance
 *
 * ] * @return the {@link HttpSecurity}/*from ww w  . j a v a2  s . c  om*/
 * @throws Exception
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected final HttpSecurity getHttp() throws Exception {
    if (http != null) {
        return http;
    }

    DefaultAuthenticationEventPublisher eventPublisher = objectPostProcessor
            .postProcess(new DefaultAuthenticationEventPublisher());
    localConfigureAuthenticationBldr.authenticationEventPublisher(eventPublisher);

    AuthenticationManager authenticationManager = authenticationManager();
    authenticationBuilder.parentAuthenticationManager(authenticationManager);
    authenticationBuilder.authenticationEventPublisher(eventPublisher);
    Map<Class<? extends Object>, Object> sharedObjects = createSharedObjects();

    http = new HttpSecurity(objectPostProcessor, authenticationBuilder, sharedObjects);
    if (!disableDefaults) {
        // @formatter:off
        http.csrf().and().addFilter(new WebAsyncManagerIntegrationFilter()).exceptionHandling().and().headers()
                .and().sessionManagement().and().securityContext().and().requestCache().and().anonymous().and()
                .servletApi().and().apply(new DefaultLoginPageConfigurer<>()).and().logout();
        // @formatter:on
        ClassLoader classLoader = this.context.getClassLoader();
        List<AbstractHttpConfigurer> defaultHttpConfigurers = SpringFactoriesLoader
                .loadFactories(AbstractHttpConfigurer.class, classLoader);

        for (AbstractHttpConfigurer configurer : defaultHttpConfigurers) {
            http.apply(configurer);
        }
    }
    configure(http);
    return http;
}

From source file:org.springframework.test.context.support.AbstractTestContextBootstrapper.java

/**
 * Get the {@link ContextCustomizerFactory} instances for this bootstrapper.
 * <p>The default implementation uses the {@link SpringFactoriesLoader} mechanism
 * for loading factories configured in all {@code META-INF/spring.factories}
 * files on the classpath./* w  w w  .ja  va  2 s  .c o m*/
 * @since 4.3
 * @see SpringFactoriesLoader#loadFactories
 */
protected List<ContextCustomizerFactory> getContextCustomizerFactories() {
    return SpringFactoriesLoader.loadFactories(ContextCustomizerFactory.class, getClass().getClassLoader());
}