org.springframework.beans.factory.access.BeanFactoryLocator Java Examples
The following examples show how to use
org.springframework.beans.factory.access.BeanFactoryLocator.
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: ContextSingletonBeanFactoryLocator.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Returns an instance which uses the specified selector, as the name of the * definition file(s). In the case of a name with a Spring "classpath*:" prefix, * or with no prefix, which is treated the same, the current thread's context class * loader's {@code getResources} method will be called with this value to get * all resources having that name. These resources will then be combined to form a * definition. In the case where the name uses a Spring "classpath:" prefix, or * a standard URL prefix, then only one resource file will be loaded as the * definition. * @param selector the location of the resource(s) which will be read and * combined to form the definition for the BeanFactoryLocator instance. * Any such files must form a valid ApplicationContext definition. * @return the corresponding BeanFactoryLocator instance * @throws BeansException in case of factory loading failure */ public static BeanFactoryLocator getInstance(String selector) throws BeansException { String resourceLocation = selector; if (resourceLocation == null) { resourceLocation = DEFAULT_RESOURCE_LOCATION; } // For backwards compatibility, we prepend "classpath*:" to the selector name if there // is no other prefix (i.e. "classpath*:", "classpath:", or some URL prefix). if (!ResourcePatternUtils.isUrl(resourceLocation)) { resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation; } synchronized (instances) { if (logger.isTraceEnabled()) { logger.trace("ContextSingletonBeanFactoryLocator.getInstance(): instances.hashCode=" + instances.hashCode() + ", instances=" + instances); } BeanFactoryLocator bfl = instances.get(resourceLocation); if (bfl == null) { bfl = new ContextSingletonBeanFactoryLocator(resourceLocation); instances.put(resourceLocation, bfl); } return bfl; } }
Example #2
Source File: ContextSingletonBeanFactoryLocator.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Returns an instance which uses the the specified selector, as the name of the * definition file(s). In the case of a name with a Spring "classpath*:" prefix, * or with no prefix, which is treated the same, the current thread's context class * loader's {@code getResources} method will be called with this value to get * all resources having that name. These resources will then be combined to form a * definition. In the case where the name uses a Spring "classpath:" prefix, or * a standard URL prefix, then only one resource file will be loaded as the * definition. * @param selector the location of the resource(s) which will be read and * combined to form the definition for the BeanFactoryLocator instance. * Any such files must form a valid ApplicationContext definition. * @return the corresponding BeanFactoryLocator instance * @throws BeansException in case of factory loading failure */ public static BeanFactoryLocator getInstance(String selector) throws BeansException { String resourceLocation = selector; if (resourceLocation == null) { resourceLocation = DEFAULT_RESOURCE_LOCATION; } // For backwards compatibility, we prepend "classpath*:" to the selector name if there // is no other prefix (i.e. "classpath*:", "classpath:", or some URL prefix). if (!ResourcePatternUtils.isUrl(resourceLocation)) { resourceLocation = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resourceLocation; } synchronized (instances) { if (logger.isTraceEnabled()) { logger.trace("ContextSingletonBeanFactoryLocator.getInstance(): instances.hashCode=" + instances.hashCode() + ", instances=" + instances); } BeanFactoryLocator bfl = instances.get(resourceLocation); if (bfl == null) { bfl = new ContextSingletonBeanFactoryLocator(resourceLocation); instances.put(resourceLocation, bfl); } return bfl; } }
Example #3
Source File: ContextSingletonBeanFactoryLocatorTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * This test can run multiple times, but due to static keyed lookup of the locators, * 2nd and subsequent calls will actually get back same locator instance. This is not * really an issue, since the contained bean factories will still be loaded and released. */ @Override @Test public void testGetInstance() { // Try with and without 'classpath*:' prefix, and with 'classpath:' prefix. BeanFactoryLocator facLoc = ContextSingletonBeanFactoryLocator.getInstance( ClassUtils.addResourcePathToPackagePath(CLASS, CONTEXT)); getInstanceTest1(facLoc); facLoc = ContextSingletonBeanFactoryLocator.getInstance( "classpath*:" + ClassUtils.addResourcePathToPackagePath(CLASS, CONTEXT)); getInstanceTest2(facLoc); // This will actually get another locator instance, as the key is the resource name. facLoc = ContextSingletonBeanFactoryLocator.getInstance( "classpath:" + ClassUtils.addResourcePathToPackagePath(CLASS, CONTEXT)); getInstanceTest3(facLoc); }
Example #4
Source File: ComponentLoaderImpl.java From zstack with Apache License 2.0 | 5 votes |
public ComponentLoaderImpl () { checkInit(); BeanFactoryLocator factoryLocator = ContextSingletonBeanFactoryLocator .getInstance(String.format("classpath:%s", CoreGlobalProperty.BEAN_REF_CONTEXT_CONF)); BeanFactoryReference ref = factoryLocator.useBeanFactory("parentContext"); ioc = ref.getFactory(); }
Example #5
Source File: EtlExecutorBean.java From scriptella-etl with Apache License 2.0 | 5 votes |
/** * 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); }
Example #6
Source File: DefaultLocatorFactoryTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void getInstance() { BeanFactoryLocator bf = DefaultLocatorFactory.getInstance(); BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance(); assertTrue(bf.equals(bf2)); }
Example #7
Source File: DefaultLocatorFactoryTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void getInstanceString() { BeanFactoryLocator bf = DefaultLocatorFactory.getInstance("my-bean-refs.xml"); BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance("my-bean-refs.xml"); assertTrue(bf.equals(bf2)); }
Example #8
Source File: ContextSingletonBeanFactoryLocator.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Returns an instance which uses the default "classpath*:beanRefContext.xml", as * the name of the definition file(s). All resources returned by the current * thread's context class loader's {@code getResources} method with this * name will be combined to create a definition, which is just a BeanFactory. * @return the corresponding BeanFactoryLocator instance * @throws BeansException in case of factory loading failure */ public static BeanFactoryLocator getInstance() throws BeansException { return getInstance(null); }
Example #9
Source File: DefaultLocatorFactory.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Return an instance object implementing BeanFactoryLocator. This will normally * be a singleton instance of the specific ContextSingletonBeanFactoryLocator class, * using the default resource selector. */ public static BeanFactoryLocator getInstance() throws FatalBeanException { return ContextSingletonBeanFactoryLocator.getInstance(); }
Example #10
Source File: DefaultLocatorFactory.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Return an instance object implementing BeanFactoryLocator. This will normally * be a singleton instance of the specific ContextSingletonBeanFactoryLocator class, * using the specified resource selector. * @param selector a selector variable which provides a hint to the factory as to * which instance to return. */ public static BeanFactoryLocator getInstance(String selector) throws FatalBeanException { return ContextSingletonBeanFactoryLocator.getInstance(selector); }
Example #11
Source File: SpringBeanAutowiringInterceptor.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Determine the BeanFactoryLocator to obtain the BeanFactoryReference from. * <p>The default implementation exposes Spring's default * {@link ContextSingletonBeanFactoryLocator}. * @param target the target bean to autowire * @return the BeanFactoryLocator to use (never {@code null}) * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator#getInstance() */ protected BeanFactoryLocator getBeanFactoryLocator(Object target) { return ContextSingletonBeanFactoryLocator.getInstance(); }
Example #12
Source File: ContextSingletonBeanFactoryLocator.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Returns an instance which uses the default "classpath*:beanRefContext.xml", as * the name of the definition file(s). All resources returned by the current * thread's context class loader's {@code getResources} method with this * name will be combined to create a definition, which is just a BeanFactory. * @return the corresponding BeanFactoryLocator instance * @throws BeansException in case of factory loading failure */ public static BeanFactoryLocator getInstance() throws BeansException { return getInstance(null); }
Example #13
Source File: DefaultLocatorFactory.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Return an instance object implementing BeanFactoryLocator. This will normally * be a singleton instance of the specific ContextSingletonBeanFactoryLocator class, * using the default resource selector. */ public static BeanFactoryLocator getInstance() throws FatalBeanException { return ContextSingletonBeanFactoryLocator.getInstance(); }
Example #14
Source File: DefaultLocatorFactory.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Return an instance object implementing BeanFactoryLocator. This will normally * be a singleton instance of the specific ContextSingletonBeanFactoryLocator class, * using the specified resource selector. * @param selector a selector variable which provides a hint to the factory as to * which instance to return. */ public static BeanFactoryLocator getInstance(String selector) throws FatalBeanException { return ContextSingletonBeanFactoryLocator.getInstance(selector); }
Example #15
Source File: SpringBeanAutowiringInterceptor.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Determine the BeanFactoryLocator to obtain the BeanFactoryReference from. * <p>The default implementation exposes Spring's default * {@link ContextSingletonBeanFactoryLocator}. * @param target the target bean to autowire * @return the BeanFactoryLocator to use (never {@code null}) * @see org.springframework.context.access.ContextSingletonBeanFactoryLocator#getInstance() */ protected BeanFactoryLocator getBeanFactoryLocator(Object target) { return ContextSingletonBeanFactoryLocator.getInstance(); }