当前位置: 首页>>代码示例>>Java>>正文


Java SpringFactoriesLoader.loadFactoryNames方法代码示例

本文整理汇总了Java中org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames方法的典型用法代码示例。如果您正苦于以下问题:Java SpringFactoriesLoader.loadFactoryNames方法的具体用法?Java SpringFactoriesLoader.loadFactoryNames怎么用?Java SpringFactoriesLoader.loadFactoryNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.core.io.support.SpringFactoriesLoader的用法示例。


在下文中一共展示了SpringFactoriesLoader.loadFactoryNames方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildInitializer

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
protected T buildInitializer(Supplier<T> defaultSupplier, Object ... args) {
    List<String> initClassNames = SpringFactoriesLoader.loadFactoryNames(initClass, Thread.currentThread().getContextClassLoader());

    if (initClassNames.isEmpty()) {
        return defaultSupplier.get();
    }

    List<Class<?>> initClasses = ClassUtils.convertClassNamesToClasses(initClassNames);

    initClasses.sort(AnnotationAwareOrderComparator.INSTANCE);

    Class<?> primaryInitClass = initClasses.get(0);

    try {
        return this.initClass.cast(ConstructorUtils.invokeConstructor(primaryInitClass, args));
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
        throw new ApplicationContextException(String.format("Unable to instantiate application initializer (class=%s).", primaryInitClass.getName()), e);
    }
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:20,代码来源:AbstractApplicationInitializerRunListener.java

示例2: buildComponent

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
protected static <T> T buildComponent(Class<T> componentClass, Supplier<T> defaultSupplier, Object ... args) {
    List<String> componentClassNames = SpringFactoriesLoader.loadFactoryNames(componentClass, AbstractCrigttApplicationRunListener.class.getClassLoader());

    if (componentClassNames.isEmpty()) {
        return defaultSupplier.get();
    }

    List<Class<?>> componentClasses = ClassUtils.convertClassNamesToClasses(componentClassNames);

    componentClasses.sort(AnnotationAwareOrderComparator.INSTANCE);

    Class<?> primaryComponentClass = componentClasses.get(0);

    try {
        return componentClass.cast(ConstructorUtils.invokeConstructor(primaryComponentClass, args));
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
        throw new ApplicationContextException(String.format("Unable to instantiate component (class=%s).", primaryComponentClass.getName()), e);
    }
}
 
开发者ID:esacinc,项目名称:crigtt,代码行数:20,代码来源:AbstractCrigttApplicationRunListener.java

示例3: test02

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
@Test
public void test02() {
    List<String> classes = SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class, this.getClass().getClassLoader());
    classes.forEach(clazz -> {
        System.out.println("==== " + clazz);
    });
}
 
开发者ID:fangjian0423,项目名称:springboot-analysis,代码行数:8,代码来源:LoadTest.java

示例4: getSpringFactoriesInstances

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
private <T> Collection<? extends T> getSpringFactoriesInstances(Class<T> type,
		Class<?>[] parameterTypes, Object... args) {
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
	// Use names and ensure unique to protect against duplicates
	Set<String> names = new LinkedHashSet<String>(
			SpringFactoriesLoader.loadFactoryNames(type, classLoader));
	List<T> instances = createSpringFactoriesInstances(type, parameterTypes,
			classLoader, args, names);
	AnnotationAwareOrderComparator.sort(instances);
	return instances;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:SpringApplication.java

示例5: selectImports

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
@Override
public String[] selectImports(AnnotationMetadata metadata) {
	// Find all possible auto configuration classes, filtering duplicates
	List<String> factories = new ArrayList<String>(
			new LinkedHashSet<String>(SpringFactoriesLoader.loadFactoryNames(
					ManagementContextConfiguration.class, this.classLoader)));
	AnnotationAwareOrderComparator.sort(factories);
	return factories.toArray(new String[0]);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ManagementContextConfigurationsImportSelector.java

示例6: getConfigurationsForAnnotation

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
private Collection<String> getConfigurationsForAnnotation(Class<?> source,
		Annotation annotation) {
	String[] value = (String[]) AnnotationUtils
			.getAnnotationAttributes(annotation, true).get("value");
	if (value.length > 0) {
		return Arrays.asList(value);
	}
	return SpringFactoriesLoader.loadFactoryNames(source,
			getClass().getClassLoader());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:ImportAutoConfigurationImportSelector.java

示例7: getCandidateConfigurations

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
/**
 * Return the auto-configuration class names that should be considered. By default
 * this method will load candidates using {@link SpringFactoriesLoader} with
 * {@link #getSpringFactoriesLoaderFactoryClass()}.
 * @param metadata the source metadata
 * @param attributes the {@link #getAttributes(AnnotationMetadata) annotation
 * attributes}
 * @return a list of candidate configurations
 */
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata,
		AnnotationAttributes attributes) {
	List<String> configurations = SpringFactoriesLoader.loadFactoryNames(
			getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader());
	Assert.notEmpty(configurations,
			"No auto configuration classes found in META-INF/spring.factories. If you "
					+ "are using a custom packaging, make sure that file is correct.");
	return configurations;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:EnableAutoConfigurationImportSelector.java

示例8: getCandidateConfigurations

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
/**
 * Return the HTTP client class names that should be considered. By default
 * this method will load candidates using {@link SpringFactoriesLoader} with
 * {@link #getSpringFactoriesLoaderFactoryClass()}.
 * attributes}
 * @return a list of candidate configurations
 */
protected List<String> getCandidateConfigurations() {
    List<String> configurations = SpringFactoriesLoader.loadFactoryNames(
            getSpringFactoriesLoaderFactoryClass(), this.getClass().getClassLoader());
    Assert.notEmpty(configurations,
            "No HTTP client classes found in META-INF/spring.factories. If you" +
                    "are using a custom packaging, make sure that file is correct.");
    return configurations;
}
 
开发者ID:gravitee-io,项目名称:gravitee-gateway,代码行数:16,代码来源:HttpClientConfigurationImportSelector.java

示例9: getSpringFactoriesInstances

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Collection<? extends T> getSpringFactoriesInstances(Class<T> type,
		Class<?>[] parameterTypes, Object... args) {
	ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

	// Use names and ensure unique to protect against duplicates
	Set<String> names = new LinkedHashSet<String>(
			SpringFactoriesLoader.loadFactoryNames(type, classLoader));
	List<T> instances = new ArrayList<T>(names.size());

	// Create instances from the names
	for (String name : names) {
		try {
			Class<?> instanceClass = ClassUtils.forName(name, classLoader);
			Assert.isAssignable(type, instanceClass);
			Constructor<?> constructor = instanceClass.getConstructor(parameterTypes);
			T instance = (T) constructor.newInstance(args);
			instances.add(instance);
		}
		catch (Throwable ex) {
			throw new IllegalArgumentException(
					"Cannot instantiate " + type + " : " + name, ex);
		}
	}

	AnnotationAwareOrderComparator.sort(instances);
	return instances;
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:29,代码来源:SpringApplication.java

示例10: getSpringFactoriesInstances

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
private <T> Collection<? extends T> getSpringFactoriesInstances(Class<T> type,
                                                                Class<?>[] parameterTypes, Object... args) {
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    Set<String> names = new LinkedHashSet<>(
            SpringFactoriesLoader.loadFactoryNames(type, classLoader));
    List<T> instances = createSpringFactoriesInstances(type, parameterTypes,
            classLoader, args, names);
    AnnotationAwareOrderComparator.sort(instances);
    return instances;
}
 
开发者ID:wso2,项目名称:msf4j,代码行数:11,代码来源:MSF4JSpringApplication.java

示例11: selectImports

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
@Override
public String[] selectImports(AnnotationMetadata metadata) {
	if (!isEnabled()) {
		return new String[0];
	}
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(
			metadata.getAnnotationAttributes(this.annotationClass.getName(), true));

	Assert.notNull(attributes, "No " + getSimpleName() + " attributes found. Is "
			+ metadata.getClassName() + " annotated with @" + getSimpleName() + "?");

	// Find all possible auto configuration classes, filtering duplicates
	List<String> factories = new ArrayList<>(new LinkedHashSet<>(SpringFactoriesLoader
			.loadFactoryNames(this.annotationClass, this.beanClassLoader)));

	if (factories.isEmpty() && !hasDefaultFactory()) {
		throw new IllegalStateException("Annotation @" + getSimpleName()
				+ " found, but there are no implementations. Did you forget to include a starter?");
	}

	if (factories.size() > 1) {
		// there should only ever be one DiscoveryClient, but there might be more than
		// one factory
		log.warn("More than one implementation " + "of @" + getSimpleName()
				+ " (now relying on @Conditionals to pick one): " + factories);
	}

	return factories.toArray(new String[factories.size()]);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:30,代码来源:SpringFactoryImportSelector.java

示例12: getConfigurations

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
private List<String> getConfigurations() {
    return SpringFactoriesLoader.loadFactoryNames(Configuration.class, Thread.currentThread().getContextClassLoader());
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:4,代码来源:LodsveExtConfigurationLoader.java

示例13: getAutoConfigurationClassNames

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
private List<String> getAutoConfigurationClassNames() {
	return SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class,
			getClass().getClassLoader());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:5,代码来源:EnableAutoConfigurationImportSelectorTests.java

示例14: doSelect

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
@Override
protected List<String> doSelect(AnnotationMetadata metadata, AnnotationAttributes attributes) {
	List<String> classNames = new ArrayList<String>();
	
	if(attributes.getBoolean("enableCommonService")){
		classNames.add(BootCommonServiceConfig.class.getName());
	}
	
	AppcationType appcationType = (AppcationType)attributes.get("appcationType");
	if(appcationType==AppcationType.WEB_SERVICE){
		classNames.add(BootMSContextAutoConfig.class.getName());
	}else if(appcationType==AppcationType.WEB_UI){
		classNames.add(BootWebUIContextAutoConfig.class.getName());
	}
	classNames.add(ErrorHandleConfiguration.class.getName());
	classNames.add(EnhanceRequestMappingConfiguration.class.getName());

	classNames.add(JwtContextConfig.class.getName());
	
	classNames.add(OAuth2SsoClientAutoContextConfig.class.getName());
	classNames.add(RedisConfiguration.class.getName());
	classNames.add(AsyncMvcConfiguration.class.getName());
	classNames.add(AsyncTaskConfiguration.class.getName());
	classNames.add(AccessLogConfiguration.class.getName());
	classNames.add(GraceKillConfiguration.class.getName());

	//cache
	classNames.add(SpringCacheConfiguration.class.getName());
	classNames.add(RedissonConfiguration.class.getName());
	
	Collection<String> exts = new LinkedHashSet<>(SpringFactoriesLoader.loadFactoryNames(this.annotationClass, this.beanClassLoader));
	for(String extClassName : exts){
		Class<?> extClass;
		try {
			extClass = ClassUtils.forName(extClassName, beanClassLoader);
		} catch (ClassNotFoundException | LinkageError e) {
			throw new BaseException("load "+this.annotationClass.getSimpleName()+" error. extension class: " + extClassName, e);
		}
		if(extClass.getAnnotation(JFishWebPlugin.class)==null){
			throw new BaseException("extension class["+extClassName+"] must be annotated by "+JFishWebPlugin.class.getName());
		}
		classNames.add(extClassName);
	}
	
	
	return classNames;
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:48,代码来源:EnableJFishBootExtensionSelector.java

示例15: test

import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
@Test
public void test(){
	List<String> names = SpringFactoriesLoader.loadFactoryNames(EnableAutoConfiguration.class, ClassUtils.getDefaultClassLoader());
	System.out.println("names:"+names);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:6,代码来源:SpringFactoriesLoaderTest.java


注:本文中的org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。