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

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

Introduction

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

Prototype

public ControllerAdviceBean(String beanName, BeanFactory beanFactory) 

Source Link

Document

Create a ControllerAdviceBean using the given bean name and BeanFactory .

Usage

From source file:org.springframework.web.method.ControllerAdviceBean.java

/**
 * Find the names of beans annotated with
 * {@linkplain ControllerAdvice @ControllerAdvice} in the given
 * ApplicationContext and wrap them as {@code ControllerAdviceBean} instances.
 *///w  w  w  . j a va  2s. c o m
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext applicationContext) {
    List<ControllerAdviceBean> beans = new ArrayList<ControllerAdviceBean>();
    for (String name : BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, Object.class)) {
        if (applicationContext.findAnnotationOnBean(name, ControllerAdvice.class) != null) {
            beans.add(new ControllerAdviceBean(name, applicationContext));
        }
    }
    return beans;
}