org.springframework.core.io.support.SpringFactoriesLoader#loadFactories ( )源码实例Demo

下面列出了org.springframework.core.io.support.SpringFactoriesLoader#loadFactories ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@SuppressWarnings("unchecked")
@Substitute
private <T> Collection<T> getSpringFactoriesInstances(Class<T> type, Class<?>[] parameterTypes, Object... args) {
	List<T> instances;
	if (type.equals(SpringApplicationRunListener.class)) {
		instances = (List<T>) Arrays.asList(new EventPublishingRunListener((SpringApplication)(Object)this, new String[0])); // TODO convert args
		// Error when using it, and we probably should do that at build time
		//AnnotationAwareOrderComparator.sort(instances);
	}
	else if (type.equals(SpringBootExceptionReporter.class)) {
		instances = (List<T>) Arrays.asList(DiagnosticsProvider.getFailureAnalyzers((ConfigurableApplicationContext) args[0])); // Package private
		// Error when using it, and we probably should do that at build time
		//AnnotationAwareOrderComparator.sort(instances);
	}
	else {
		instances = SpringFactoriesLoader.loadFactories(type, null);
	}
	return instances;
}
 
源代码2 项目: spring-cloud-contract   文件: StubRepository.java
StubRepository(File repository, List<HttpServerStub> httpServerStubs,
		StubRunnerOptions options) {
	if (!repository.isDirectory()) {
		throw new IllegalArgumentException(
				"Missing descriptor repository under path [" + repository + "]");
	}
	this.contractConverters = SpringFactoriesLoader
			.loadFactories(ContractConverter.class, null);
	if (log.isTraceEnabled()) {
		log.trace(
				"Found the following contract converters " + this.contractConverters);
	}
	this.httpServerStubs = httpServerStubs;
	this.path = repository;
	this.options = options;
	this.stubs = stubs();
	this.contracts = contracts();
	if (log.isTraceEnabled()) {
		log.trace("Found the following contracts " + this.contracts);
	}
}
 
源代码3 项目: mPaaS   文件: DefaultConfigListener.java
@Override
public void starting() {
    if (executed.compareAndSet(false, true)) {
        List<DefaultConfigFactory> defaultConfigs = SpringFactoriesLoader.loadFactories(DefaultConfigFactory.class, this.getClass().getClassLoader());
        Map<String, Object> defaultConfig = new Hashtable<>(1);
        for (DefaultConfigFactory defaultConfigFactory : defaultConfigs) {
            defaultConfig.putAll(defaultConfigFactory.defaultConfig());
        }
        springApplication.setDefaultProperties(defaultConfig);
    }
}
 
源代码4 项目: mPass   文件: DefaultConfigListener.java
@Override
public void starting() {
    if (executed.compareAndSet(false, true)) {
        List<DefaultConfigFactory> defaultConfigs = SpringFactoriesLoader.loadFactories(DefaultConfigFactory.class, this.getClass().getClassLoader());
        Map<String, Object> defaultConfig = new Hashtable<>(1);
        for (DefaultConfigFactory defaultConfigFactory : defaultConfigs) {
            defaultConfig.putAll(defaultConfigFactory.defaultConfig());
        }
        springApplication.setDefaultProperties(defaultConfig);
    }
}
 
@Override
public void environmentPrepared(ConfigurableEnvironment env) {
    if("bootstrap".equals(env.getProperty("spring.config.name"))) {
        List<EnvironmentCustomizer> environmentCustomizers =
                SpringFactoriesLoader.loadFactories(EnvironmentCustomizer.class, AdminEndpointApplicationRunListener.class.getClassLoader());
        if(CollectionUtils.isEmpty(environmentCustomizers)) return;
        for(EnvironmentCustomizer customizer: environmentCustomizers) {
            customizer.customize(env);
        }
    }
}
 
@Override
public void environmentPrepared(ConfigurableEnvironment env) {
    if("bootstrap".equals(env.getProperty("spring.config.name"))) {
        List<EnvironmentCustomizer> environmentCustomizers =
        SpringFactoriesLoader.loadFactories(EnvironmentCustomizer.class, AdminEndpointApplicationRunListener.class.getClassLoader());
        if(CollectionUtils.isEmpty(environmentCustomizers)) return;
        for(EnvironmentCustomizer customizer: environmentCustomizers) {
            customizer.customize(env);
        }
    }

}
 
源代码7 项目: spi-imp   文件: SpringSPITest.java
@Test
public void sayHello() throws Exception {
    List<OrderService> services = SpringFactoriesLoader.loadFactories(OrderService.class, null);
    for (OrderService service : services) {
        service.getOrder("worder.");
    }
}
 
源代码8 项目: jim-framework   文件: AccessLimitFilter.java
@Override
public Object invoke(RpcInvoker invoker, RpcInvocation invocation) {
    logger.info("before acquire,"+new Date());
    List<AccessLimitService> accessLimitServiceLoader = SpringFactoriesLoader.loadFactories(AccessLimitService.class, null);
    if(!CollectionUtils.isEmpty(accessLimitServiceLoader)){
        AccessLimitService accessLimitService=accessLimitServiceLoader.get(0);
        accessLimitService.acquire(invocation);
    }

    Object rpcResponse=invoker.invoke(invocation);
    logger.info("after acquire,"+new Date());
    return rpcResponse;
}
 
源代码9 项目: apollo   文件: BootstrapConfigTest.java
@Test
public void test() {
  List<EnvironmentPostProcessor> processorList =  SpringFactoriesLoader.loadFactories(EnvironmentPostProcessor.class, getClass().getClassLoader());

  Boolean containsApollo = !Collections2.filter(processorList, new Predicate<EnvironmentPostProcessor>() {
        @Override
        public boolean apply(EnvironmentPostProcessor input) {
            return input instanceof ApolloApplicationContextInitializer;
        }
    }).isEmpty();
  Assert.assertTrue(containsApollo);
}
 
源代码10 项目: spring-cloud-contract   文件: StubRunner.java
public StubRunner(StubRunnerOptions stubRunnerOptions, String repositoryPath,
		StubConfiguration stubsConfiguration,
		MessageVerifier<?> contractVerifierMessaging) {
	this.stubsConfiguration = stubsConfiguration;
	this.stubRunnerOptions = stubRunnerOptions;
	List<HttpServerStub> serverStubs = SpringFactoriesLoader
			.loadFactories(HttpServerStub.class, null);
	this.stubRepository = new StubRepository(new File(repositoryPath), serverStubs,
			this.stubRunnerOptions);
	AvailablePortScanner portScanner = new AvailablePortScanner(
			stubRunnerOptions.getMinPortValue(), stubRunnerOptions.getMaxPortValue());
	this.localStubRunner = new StubRunnerExecutor(portScanner,
			contractVerifierMessaging, serverStubs);
}
 
private Extension[] responseTransformers() {
	List<WireMockExtensions> wireMockExtensions = SpringFactoriesLoader
			.loadFactories(WireMockExtensions.class, null);
	List<Extension> extensions = new ArrayList<>();
	if (!wireMockExtensions.isEmpty()) {
		for (WireMockExtensions wireMockExtension : wireMockExtensions) {
			extensions.addAll(wireMockExtension.extensions());
		}
	}
	else {
		extensions.add(new DefaultResponseTransformer(false, helpers()));
	}
	return extensions.toArray(new Extension[extensions.size()]);
}
 
Loader(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
    this.environment = environment;
    this.resourceLoader = resourceLoader == null ? new DefaultResourceLoader()
        : resourceLoader;
    this.propertySourceLoaders = SpringFactoriesLoader.loadFactories(
        PropertySourceLoader.class, getClass().getClassLoader());
}
 
public MagicPropertySourcePostProcessor() {
	this.resourceLoader = new DefaultResourceLoader();
	this.propertySourceLoaders = SpringFactoriesLoader.loadFactories(PropertySourceLoader.class, getClass().getClassLoader());
}
 
源代码14 项目: java-cfenv   文件: BootIntegrationTest.java
@Test
public void test() {
	// Should not throw exception
	SpringFactoriesLoader.loadFactories(CfEnvProcessor.class, getClass().getClassLoader());
}
 
private List<PropertySourceLoader> initPropertyLoaders() {
    return SpringFactoriesLoader.loadFactories(PropertySourceLoader.class, getClass().getClassLoader());
}
 
/**
 * 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.
 * @since 4.3
 * @see SpringFactoriesLoader#loadFactories
 */
protected List<ContextCustomizerFactory> getContextCustomizerFactories() {
	return SpringFactoriesLoader.loadFactories(ContextCustomizerFactory.class, getClass().getClassLoader());
}
 
/**
 * 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.
 * @since 4.3
 * @see SpringFactoriesLoader#loadFactories
 */
protected List<ContextCustomizerFactory> getContextCustomizerFactories() {
	return SpringFactoriesLoader.loadFactories(ContextCustomizerFactory.class, getClass().getClassLoader());
}