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

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

Introduction

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

Prototype

String[] getBeanNamesForType(@Nullable Class<?> type);

Source Link

Document

Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Usage

From source file:org.springframework.flex.messaging.MessageTemplate.java

/**
 * //from ww  w .  j a  v  a  2s . c  om
 * {@inheritDoc}
 */
public void afterPropertiesSet() throws Exception {
    if (this.messageBroker == null) {
        // first try the default id
        if (this.beanFactory.containsBean(BeanIds.MESSAGE_BROKER)) {
            this.messageBroker = (MessageBroker) this.beanFactory.getBean(BeanIds.MESSAGE_BROKER,
                    MessageBroker.class);
        } else if (this.beanFactory instanceof ListableBeanFactory) {
            ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory;
            String[] brokerNames = lbf.getBeanNamesForType(MessageBroker.class);
            if (brokerNames.length == 1) {
                this.messageBroker = (MessageBroker) lbf.getBean(brokerNames[0]);
            } else if (brokerNames.length > 1) {
                log.warn(
                        "A MessageBroker was not explicitly set and one could not be auto-detected in the MessageTemplate's bean factory as "
                                + "multiple MessageBrokers were found.  Will fall back to attempting to obtain the MessageBroker from the FlexContext for "
                                + "each operation.");
            } else {
                log.warn(
                        "A MessageBroker was not explicitly set and one could not be found in the MessageTemplate's bean factory.  Will "
                                + "will fall back to attempting to obtain the MessageBroker from the FlexContext for each operation.");
            }
        }
    }
}