本文整理汇总了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);
}
}
示例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);
}
}
示例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);
});
}
示例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;
}
示例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;
}
示例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;
}
示例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()]);
}
示例12: getConfigurations
import org.springframework.core.io.support.SpringFactoriesLoader; //导入方法依赖的package包/类
private List<String> getConfigurations() {
return SpringFactoriesLoader.loadFactoryNames(Configuration.class, Thread.currentThread().getContextClassLoader());
}
示例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;
}
示例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);
}