Example usage for org.springframework.context ConfigurableApplicationContext getType

List of usage examples for org.springframework.context ConfigurableApplicationContext getType

Introduction

In this page you can find the example usage for org.springframework.context ConfigurableApplicationContext getType.

Prototype

@Nullable
Class<?> getType(String name) throws NoSuchBeanDefinitionException;

Source Link

Document

Determine the type of the bean with the given name.

Usage

From source file:jetbrains.buildServer.server.rest.jersey.JerseyWebComponent.java

/**
 * Checks for all beans that have @Provider annotation and
 * registers them into Jersey ResourceConfig
 * @param rc config/*  w ww. j a v  a2s  . co  m*/
 * @param springContext spring context
 */
private void registerResourceProfiders(ResourceConfig rc, ConfigurableApplicationContext springContext) {
    //TODO: restrict search to current spring context without parent for speedup
    for (String name : BeanFactoryUtils.beanNamesIncludingAncestors(springContext)) {
        final Class<?> type = ClassUtils.getUserClass(springContext.getType(name));
        if (ResourceConfig.isProviderClass(type)) {
            LOG.info("Registering Spring bean, " + name + ", of type " + type.getName()
                    + " as a provider class");
            rc.getClasses().add(type);
        } else if (ResourceConfig.isRootResourceClass(type)) {
            LOG.info("Registering Spring bean, " + name + ", of type " + type.getName()
                    + " as a root resource class");
            rc.getClasses().add(type);
        }
    }
}

From source file:org.springframework.context.event.EventListenerMethodProcessor.java

protected void processBean(final List<EventListenerFactory> factories, final String beanName,
        final Class<?> targetType) {

    if (!this.nonAnnotatedClasses.contains(targetType)) {
        Map<Method, EventListener> annotatedMethods = null;
        try {//  w ww  .  ja  va2 s  .com
            annotatedMethods = MethodIntrospector.selectMethods(targetType,
                    (MethodIntrospector.MetadataLookup<EventListener>) method -> AnnotatedElementUtils
                            .findMergedAnnotation(method, EventListener.class));
        } catch (Throwable ex) {
            // An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.
            if (logger.isDebugEnabled()) {
                logger.debug("Could not resolve methods for bean with name '" + beanName + "'", ex);
            }
        }
        if (CollectionUtils.isEmpty(annotatedMethods)) {
            this.nonAnnotatedClasses.add(targetType);
            if (logger.isTraceEnabled()) {
                logger.trace("No @EventListener annotations found on bean class: " + targetType.getName());
            }
        } else {
            // Non-empty set of methods
            ConfigurableApplicationContext context = getApplicationContext();
            for (Method method : annotatedMethods.keySet()) {
                for (EventListenerFactory factory : factories) {
                    if (factory.supportsMethod(method)) {
                        Method methodToUse = AopUtils.selectInvocableMethod(method, context.getType(beanName));
                        ApplicationListener<?> applicationListener = factory.createApplicationListener(beanName,
                                targetType, methodToUse);
                        if (applicationListener instanceof ApplicationListenerMethodAdapter) {
                            ((ApplicationListenerMethodAdapter) applicationListener).init(context,
                                    this.evaluator);
                        }
                        context.addApplicationListener(applicationListener);
                        break;
                    }
                }
            }
            if (logger.isDebugEnabled()) {
                logger.debug(annotatedMethods.size() + " @EventListener methods processed on bean '" + beanName
                        + "': " + annotatedMethods);
            }
        }
    }
}