org.springframework.beans.factory.access.SingletonBeanFactoryLocator Java Examples

The following examples show how to use org.springframework.beans.factory.access.SingletonBeanFactoryLocator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EtlExecutorBean.java    From scriptella-etl with Apache License 2.0 5 votes vote down vote up
/**
 * This method obtains a global ThreadLocal class independent of the classloader (JVM-scope singleton).
 * The easiest solution is to use System.getProperties().get/put, but this solution violate
 * Properties contract and have other drawbacks.
 * <p>Current solution relies on the idea behind
 * {@link org.springframework.beans.factory.access.SingletonBeanFactoryLocator}. See also bug #4648
 *
 * @return Global ThreadLocal (JVM-scope singleton).
 */
@SuppressWarnings("unchecked")
private static ThreadLocal<BeanFactory> getGlobalThreadLocal() {
    BeanFactoryLocator locator = SingletonBeanFactoryLocator.getInstance(BEAN_FACTORY_XML_PATH);
    BeanFactoryReference ref = locator.useBeanFactory(FACTORY_BEAN_NAME);
    StaticApplicationContext ctx = (StaticApplicationContext) ref.getFactory();
    if (!ctx.containsBean(THREAD_LOCAL_BEAN_NAME)) {
        ctx.registerSingleton(THREAD_LOCAL_BEAN_NAME, ThreadLocal.class);
    }
    return (ThreadLocal) ctx.getBean(THREAD_LOCAL_BEAN_NAME);
}