Example usage for org.springframework.context.annotation ClassPathBeanDefinitionScanner findCandidateComponents

List of usage examples for org.springframework.context.annotation ClassPathBeanDefinitionScanner findCandidateComponents

Introduction

In this page you can find the example usage for org.springframework.context.annotation ClassPathBeanDefinitionScanner findCandidateComponents.

Prototype

public Set<BeanDefinition> findCandidateComponents(String basePackage) 

Source Link

Document

Scan the class path for candidate components.

Usage

From source file:info.sargis.eventbus.config.EventBusHandlerBeanDefinitionParser.java

protected Set<RuntimeBeanReference> getHandlers(Element element, ParserContext parserContext) {

    String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute(BASE_PACKAGE_ATTRIBUTE),
            ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);

    ClassPathBeanDefinitionScanner scanner = configureScanner(parserContext, element);
    Set<RuntimeBeanReference> candidates = new ManagedSet<RuntimeBeanReference>(32);

    for (String basePackage : basePackages) {
        Set<BeanDefinition> components = scanner.findCandidateComponents(basePackage);
        for (BeanDefinition component : components) {
            if (isEventBusHandlerCandidate(component, parserContext)) {
                candidates.add(defineRuntimeBeanReference(parserContext, component));
            } else {
                logger.warn(String.format(
                        "Found EventBus handler candidate: %s, but without @Subscribe annotation on any public method",
                        component));/*from w w  w  .jav a2  s  .  com*/
            }
        }
    }

    return candidates;
}