Example usage for org.springframework.beans.factory.config AutowireCapableBeanFactory getBean

List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory getBean

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config AutowireCapableBeanFactory getBean.

Prototype

<T> T getBean(String name, Class<T> requiredType) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:org.echocat.jomon.spring.BeanProvider.java

@Nonnull
@Override/*from  w  w  w  .  ja v  a  2s .c o m*/
public <T> T provideFor(@Nonnull String name, @Nonnull Class<T> clazz, @Nonnull Type type) {
    final T result;
    final AutowireCapableBeanFactory beanFactory = getBeanFactory();
    if (beanFactory.containsBean(name)) {
        validateTypeAgainstBeanConfiguration(name, type);
        result = beanFactory.getBean(name, clazz);
    } else if (isCreateLocaleBeansIfNotPresentInApplicationContext()) {
        result = type == singleton ? getLocalCreatedAndConfiguredSingleton(name, clazz)
                : createInstanceAndConfigure(name, clazz);
    } else {
        throw new IllegalArgumentException("No such bean named '" + name + "' found.");
    }
    return result;
}