下面列出了怎么用org.springframework.beans.factory.access.SingletonBeanFactoryLocator的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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);
}