Example usage for org.springframework.beans.factory.config MethodInvokingFactoryBean getObject

List of usage examples for org.springframework.beans.factory.config MethodInvokingFactoryBean getObject

Introduction

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

Prototype

@Override
@Nullable
public Object getObject() throws Exception 

Source Link

Document

Returns the same value each time if the singleton property is set to "true", otherwise returns the value returned from invoking the specified method on the fly.

Usage

From source file:org.springbyexample.util.log.LoggerBeanPostProcessor.java

/**
 * Gets logger based on the logger name and type of 
 * logger (class name, ex: 'org.slf4j.Logger').
 *//*from  w  ww  . j av a  2 s.  c om*/
protected Object getLogger(String loggerName, String loggerType) {
    Object result = null;

    String staticMethod = hLoggerFactories.get(loggerType);

    if (staticMethod != null) {
        try {
            MethodInvokingFactoryBean factory = new MethodInvokingFactoryBean();
            factory.setStaticMethod(staticMethod);
            factory.setArguments(new Object[] { loggerName });
            factory.afterPropertiesSet();

            result = factory.getObject();
        } catch (Throwable e) {
            throw new FatalBeanException("Problem injecting logger.  " + e.getMessage(), e);
        }
    }

    return result;
}