Example usage for org.springframework.web.method ControllerAdviceBean getBeanType

List of usage examples for org.springframework.web.method ControllerAdviceBean getBeanType

Introduction

In this page you can find the example usage for org.springframework.web.method ControllerAdviceBean getBeanType.

Prototype

@Nullable
public Class<?> getBeanType() 

Source Link

Document

Return the type of the contained bean.

Usage

From source file:co.paralleluniverse.springframework.web.servlet.mvc.method.annotation.FiberRequestMappingHandlerAdapter.java

private void initControllerAdviceCache() {
    if (getApplicationContext() == null) {
        return;//from ww  w  . j ava 2  s .  co m
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Looking for controller advice: " + getApplicationContext());
    }

    List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(getApplicationContext());
    Collections.sort(beans, new OrderComparator());

    for (ControllerAdviceBean bean : beans) {
        Set<Method> attrMethods = HandlerMethodSelector.selectMethods(bean.getBeanType(),
                MODEL_ATTRIBUTE_METHODS);
        if (!attrMethods.isEmpty()) {
            this.modelAttributeAdviceCache.put(bean, attrMethods);
            logger.info("Detected @ModelAttribute methods in " + bean);
        }
        Set<Method> binderMethods = HandlerMethodSelector.selectMethods(bean.getBeanType(),
                INIT_BINDER_METHODS);
        if (!binderMethods.isEmpty()) {
            this.initBinderAdviceCache.put(bean, binderMethods);
            logger.info("Detected @InitBinder methods in " + bean);
        }
    }
}

From source file:org.springframework.web.reactive.result.method.annotation.ControllerMethodResolver.java

private void initControllerAdviceCaches(@Nullable ApplicationContext applicationContext) {
    if (applicationContext == null) {
        return;//  w w  w . j  a  v  a 2  s  .com
    }
    if (logger.isInfoEnabled()) {
        logger.info("Looking for @ControllerAdvice: " + applicationContext);
    }

    List<ControllerAdviceBean> beans = ControllerAdviceBean.findAnnotatedBeans(applicationContext);
    AnnotationAwareOrderComparator.sort(beans);

    for (ControllerAdviceBean bean : beans) {
        Class<?> beanType = bean.getBeanType();
        if (beanType != null) {
            Set<Method> attrMethods = selectMethods(beanType, ATTRIBUTE_METHODS);
            if (!attrMethods.isEmpty()) {
                this.modelAttributeAdviceCache.put(bean, attrMethods);
                if (logger.isInfoEnabled()) {
                    logger.info("Detected @ModelAttribute methods in " + bean);
                }
            }
            Set<Method> binderMethods = selectMethods(beanType, BINDER_METHODS);
            if (!binderMethods.isEmpty()) {
                this.initBinderAdviceCache.put(bean, binderMethods);
                if (logger.isInfoEnabled()) {
                    logger.info("Detected @InitBinder methods in " + bean);
                }
            }
            ExceptionHandlerMethodResolver resolver = new ExceptionHandlerMethodResolver(beanType);
            if (resolver.hasExceptionMappings()) {
                this.exceptionHandlerAdviceCache.put(bean, resolver);
                if (logger.isInfoEnabled()) {
                    logger.info("Detected @ExceptionHandler methods in " + bean);
                }
            }
        }
    }
}