Example usage for org.springframework.beans.factory ListableBeanFactory getBeansOfType

List of usage examples for org.springframework.beans.factory ListableBeanFactory getBeansOfType

Introduction

In this page you can find the example usage for org.springframework.beans.factory ListableBeanFactory getBeansOfType.

Prototype

<T> Map<String, T> getBeansOfType(@Nullable Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
        throws BeansException;

Source Link

Document

Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Usage

From source file:com.mtgi.analytics.servlet.BehaviorTrackingListener.java

private static void addRequestAdapters(Collection<ServletRequestBehaviorTrackingAdapter> accum,
        ListableBeanFactory beanFactory, boolean hasFilter) {
    @SuppressWarnings("unchecked")
    Collection<ServletRequestBehaviorTrackingAdapter> beans = beanFactory
            .getBeansOfType(ServletRequestBehaviorTrackingAdapter.class, false, false).values();
    if (!beans.isEmpty()) {
        if (hasFilter)
            throw new IllegalStateException(
                    "You have configured both BehaviorTrackingFilters and BehaviorTrackingListeners in the same web application.  Only one of these methods may be used in a single application.");
        accum.addAll(beans);// w  ww  . j ava  2  s  .  c  o m
    }
}

From source file:org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.java

private PropertySourcesPlaceholderConfigurer getSinglePropertySourcesPlaceholderConfigurer() {
    // Take care not to cause early instantiation of all FactoryBeans
    if (this.beanFactory instanceof ListableBeanFactory) {
        ListableBeanFactory listableBeanFactory = (ListableBeanFactory) this.beanFactory;
        Map<String, PropertySourcesPlaceholderConfigurer> beans = listableBeanFactory
                .getBeansOfType(PropertySourcesPlaceholderConfigurer.class, false, false);
        if (beans.size() == 1) {
            return beans.values().iterator().next();
        }//from   w  w  w. j  av  a 2 s.  co  m
        if (beans.size() > 1 && logger.isWarnEnabled()) {
            logger.warn("Multiple PropertySourcesPlaceholderConfigurer " + "beans registered " + beans.keySet()
                    + ", falling back to Environment");
        }
    }
    return null;
}