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


Java ClassPathScanningCandidateComponentProvider.setResourceLoader方法代码示例

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


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

示例1: getInitialEntitySet

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
private Set<Class<?>> getInitialEntitySet(BeanFactory beanFactory)
		throws ClassNotFoundException {
	Set<Class<?>> entitySet = new HashSet<Class<?>>();
	ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
			false);
	scanner.setEnvironment(this.environment);
	scanner.setResourceLoader(this.resourceLoader);
	scanner.addIncludeFilter(new AnnotationTypeFilter(Document.class));
	scanner.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
	for (String basePackage : getMappingBasePackages(beanFactory)) {
		if (StringUtils.hasText(basePackage)) {
			for (BeanDefinition candidate : scanner
					.findCandidateComponents(basePackage)) {
				entitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
						this.classLoader));
			}
		}
	}
	return entitySet;
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:21,代码来源:MongoDataAutoConfiguration.java

示例2: scanBeanDefinitions

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
public Stream<BeanDefinition> scanBeanDefinitions(Class<? extends Annotation> annoClass, String...extraPackagesToScans){
	ClassPathScanningCandidateComponentProvider scanner = createAnnotationScanner(classLoader, annoClass);
	if(resourceLoader!=null){
		scanner.setResourceLoader(resourceLoader);
	}
	/*Set<String> basePackages = getBasePackages();
	for (String basePackage : basePackages) {
		Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);
		for (BeanDefinition candidateComponent : candidateComponents) {
			consumer.accept(candidateComponent);
		}
	}*/
	Set<String> basePackages = getBasePackages();
	if(!LangUtils.isEmpty(extraPackagesToScans)){
		basePackages.addAll(Arrays.asList(extraPackagesToScans));
	}
	return basePackages.stream()
						.flatMap(pack->scanner.findCandidateComponents(pack).stream());
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:20,代码来源:AnnotationMetadataHelper.java

示例3: scanTypes

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
public static Set<Class<?>> scanTypes(String basePackage, Class<?> targetType) throws ClassNotFoundException {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    if (resourceLoader!=null) {
        scanner.setResourceLoader(resourceLoader);
    }

    AssignableTypeFilter filter = new AssignableTypeFilter(targetType);
    scanner.addIncludeFilter(filter);
    Set<BeanDefinition> beanSet = scanner.findCandidateComponents(basePackage);

    Set<Class<?>> classSet = new HashSet<Class<?>>();
    for (BeanDefinition beanDef : beanSet) {
        // log.debug("found candidate bean = {}", beanDef.getBeanClassName());

        Class<?> clazz;

        clazz = Class.forName(beanDef.getBeanClassName(), true, Thread.currentThread().getContextClassLoader());
        classSet.add(clazz);
    }

    return classSet;
}
 
开发者ID:cloudsoft,项目名称:brooklyn-tosca,代码行数:23,代码来源:TypeScanner.java

示例4: registerSoapClients

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
public void registerSoapClients(AnnotationMetadata metadata,
                                 BeanDefinitionRegistry registry) {
    ClassPathScanningCandidateComponentProvider scanner = getScanner();
    scanner.setResourceLoader(this.resourceLoader);

    AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter(
            SoapClient.class);
    scanner.addIncludeFilter(annotationTypeFilter);

    Set<String> basePackages = getBasePackages(metadata);

    for (String basePackage : basePackages) {
        Set<BeanDefinition> candidateComponents = scanner
                .findCandidateComponents(basePackage);

        for (BeanDefinition candidateComponent : candidateComponents) {
            if (candidateComponent instanceof AnnotatedBeanDefinition) {
                // verify annotated class is an interface
                AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent;
                AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
                Assert.isTrue(annotationMetadata.isInterface(),
                        "@SoapClient can only be specified on an interface");

                Map<String, Object> attributes = annotationMetadata
                        .getAnnotationAttributes(
                                SoapClient.class.getCanonicalName());
                registerSoapClient(registry, annotationMetadata, attributes);
            }
        }
    }
}
 
开发者ID:Salmondx,项目名称:spring-soap-client-starter,代码行数:32,代码来源:SoapClientRegistrar.java

示例5: scan

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
/**
 * Scan for entities with the specified annotations.
 * @param annotationTypes the annotation types used on the entities
 * @return a set of entity classes
 * @throws ClassNotFoundException if an entity class cannot be loaded
 */
@SafeVarargs
public final Set<Class<?>> scan(Class<? extends Annotation>... annotationTypes)
		throws ClassNotFoundException {
	List<String> packages = getPackages();
	if (packages.isEmpty()) {
		return Collections.<Class<?>>emptySet();
	}
	Set<Class<?>> entitySet = new HashSet<Class<?>>();
	ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
			false);
	scanner.setEnvironment(this.context.getEnvironment());
	scanner.setResourceLoader(this.context);
	for (Class<? extends Annotation> annotationType : annotationTypes) {
		scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType));
	}
	for (String basePackage : packages) {
		if (StringUtils.hasText(basePackage)) {
			for (BeanDefinition candidate : scanner
					.findCandidateComponents(basePackage)) {
				entitySet.add(ClassUtils.forName(candidate.getBeanClassName(),
						this.context.getClassLoader()));
			}
		}
	}
	return entitySet;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:33,代码来源:EntityScanner.java

示例6: scan

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
/**
 * Scan a package to find classes that have the given annotation.
 * 
 * @param packageRoot The package to scan.
 * @param anno Annotation that should be on the class that we are interested in.
 * @return A set of classes that have the annotation.
 */
public static Set<Class<?>> scan(String packageRoot, Class<? extends Annotation> anno) {
    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
    if (resourceLoader!=null) {
        scanner.setResourceLoader(resourceLoader);
    }

    AnnotationTypeFilter filter = new AnnotationTypeFilter(anno);
    scanner.addIncludeFilter(filter);
    Set<BeanDefinition> beanSet = scanner.findCandidateComponents(packageRoot);

    Set<Class<?>> classSet = new HashSet<Class<?>>();
    for (BeanDefinition beanDef : beanSet) {
        LOGGER.debug("found candidate bean = " + beanDef.getBeanClassName());

        Class<?> clazz;
        try {
            clazz = Class.forName(beanDef.getBeanClassName(), true, Thread.currentThread().getContextClassLoader());
            if (clazz.isAnnotationPresent(anno)) {
                LOGGER.debug("found annotated class, " + clazz.getName());
                classSet.add(clazz);
            }
        } catch (ClassNotFoundException e) {
            LOGGER.error("exception while scanning classpath for annotated classes", e);
        }
    }

    return classSet;
}
 
开发者ID:cloudsoft,项目名称:brooklyn-tosca,代码行数:36,代码来源:AnnotationScanner.java

示例7: refreshBundles

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
@Override
public Collection<BundleBean> refreshBundles(List<URL> urlList) throws BundleParsingException {

    final ClassPathScanningCandidateComponentProvider scanner =
            new ClassPathScanningCandidateComponentProvider(false);
    final URL[] urlArray = urlList.toArray(new URL[urlList.size()]);
    final URLClassLoader childLoader = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
        @Override
        public URLClassLoader run() {
            return new URLClassLoader(urlArray, scanner.getResourceLoader().getClassLoader());
        }
    });

    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(childLoader);
    scanner.setResourceLoader(resolver);
    scanner.setMetadataReaderFactory(new SimpleMetadataReaderFactory());
    scanner.addIncludeFilter(new AnnotationTypeFilter(org.dynamise.shared.annotation.Service.class));

    List<BundleBean> list = ConfigUtils.parsePathItems(this.propertyBean.getBundlePackages()).get().stream()
            .map(pkg -> scanner.findCandidateComponents(pkg))
            .flatMap(Collection::stream)
            .map(beanDef -> createBundleBean(childLoader, findSourceFile(beanDef), beanDef.getBeanClassName()))
            .collect(toList());

    list = shrinkDuplicates(list, list, new ArrayList<>(list.size()));
    list = shrinkDuplicates(list, this.bundleMap.values(), new ArrayList<>(list.size()));


    if (list.isEmpty()) {
        throw new BundleParsingException("No suitable bundles found");
    }

    list.stream().forEach(bundle -> this.bundleMap.values().stream().filter(current -> current.equals(bundle))
            .findFirst().ifPresent(current -> this.bundleMap.remove(current.getId())));

    list.stream().forEach(bundle -> this.bundleMap.put(bundle.getId(), bundle));

    return list;
}
 
开发者ID:efekahraman,项目名称:dynamise,代码行数:40,代码来源:DefaultBundleManager.java

示例8: postConstruct

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
@PostConstruct
public void postConstruct() {
	ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
			false);
	scanner.setEnvironment(this.environment);
	scanner.setResourceLoader(this.resourceLoader);
	scanner.addIncludeFilter(new AnnotationTypeFilter(WicketHomePage.class));
	scanner.addIncludeFilter(new AnnotationTypeFilter(WicketSignInPage.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(WicketAccessDeniedPage.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(WicketExpiredPage.class));
    scanner.addIncludeFilter(new AnnotationTypeFilter(WicketInternalErrorPage.class));
    for (String basePackage : getMappingBasePackages(beanFactory)) {
		if (StringUtils.hasText(basePackage)) {
			pageCandidates().getBasePackages().add(basePackage);
			Set<BeanDefinition> beanDefinitions = scanner.findCandidateComponents(basePackage);
			for (BeanDefinition beanDefinition : beanDefinitions) {
				Class<?> beanClass;
				try {
					beanClass = ClassUtils.forName(beanDefinition.getBeanClassName(), classLoader);
				} catch (ClassNotFoundException e) {
					throw new IllegalStateException(e);
				}
				if(beanClass.isAnnotationPresent(WicketHomePage.class)){
					pageCandidates().getHomePageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketSignInPage.class)){
					pageCandidates().getSignInPageCandidates().add(new WicketClassCandidate<WebPage>((Class<WebPage>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketAccessDeniedPage.class)){
					pageCandidates().getAccessDeniedPageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketExpiredPage.class)){
					pageCandidates().getExpiredPageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
				if(beanClass.isAnnotationPresent(WicketInternalErrorPage.class)){
					pageCandidates().getInternalErrorPageCandidates().add(new WicketClassCandidate<Page>((Class<Page>) beanClass));
				}
			}
			
		}
    }
}
 
开发者ID:MarcGiffing,项目名称:wicket-spring-boot,代码行数:43,代码来源:ClassCandidateScanner.java

示例9: findCandidateComponents

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
private Set<BeanDefinition> findCandidateComponents(ModulesConfig modulesConfig, ParserContext parser, Class<? extends Annotation> annotationType){
	ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
	scanner.addIncludeFilter(new AnnotationTypeFilter(annotationType));
	scanner.setResourceLoader(parser.getReaderContext().getResourceLoader());
	return scanner.findCandidateComponents(modulesConfig.getBasePackage());
}
 
开发者ID:u2ware,项目名称:springfield,代码行数:7,代码来源:ModulesConfigDefinitionParser.java

示例10: scan

import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; //导入方法依赖的package包/类
/**
 * Utility method to scan the given package and handler for the annotation
 * of the given class. Its uses the Spring annotation detector
 *
 * @param clas
 *            the clas
 * @param basePackage
 *            the base package
 * @param handler
 *            the handler
 */
public static void scan(final Class<? extends Annotation> clas, final String[] basePackage, final AnnotationHandler handler) {
	final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
	scanner.setResourceLoader(new PathMatchingResourcePatternResolver(Thread.currentThread().getContextClassLoader()));
	scanner.addIncludeFilter(new AnnotationTypeFilter(clas));
	for (final String pck : basePackage) {
		for (final BeanDefinition bd : scanner.findCandidateComponents(pck)) {
			handler.handleAnnotationFound(bd.getBeanClassName());
		}
	}
}
 
开发者ID:kiswanij,项目名称:jk-util,代码行数:22,代码来源:AnnotationDetector.java


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