Class SpringBeanStore
- All Implemented Interfaces:
AutoCloseable,BeanStore,WritableBeanStore
This implementation extends BasicBeanStore and delegates to Spring's ApplicationContext
for bean resolution when beans are not found in the local store or parent stores.
Example:
See Also:
-
Field Summary
Fields inherited from class org.apache.juneau.commons.inject.BasicBeanStore
INSTANCE -
Constructor Summary
ConstructorsConstructorDescriptionSpringBeanStore(org.springframework.context.ApplicationContext appContext, BeanStore parent) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionclear()Removes all beans from this store.<T> Optional<T>Returns the unnamed bean of the specified type.<T> Optional<T>Returns the named bean of the specified type.getBeansOfType(Class<T> beanType) Returns all beans of the specified type, keyed by bean name.getBeanSupplier(Class<T> beanType, String name) Returns the supplier for a named bean of the specified type.booleanReturnstrue if this store contains at least one unnamed bean of the specified type.booleanReturnstrue if this store contains a bean of the specified type and name.static booleaninvalidateEnvironmentCache(org.springframework.context.ApplicationContext appContext) Clears the miss cache of the SpringEnvironmentbridge registered for the given application context.Methods inherited from class org.apache.juneau.commons.inject.BasicBeanStore
add, add, addBean, addBean, addBeanType, addDefaultSupplier, addDefaultSupplier, addSupplier, addSupplier, close, createBeanFromMethod, getBeanSupplier, getBeanType, getDefaultSupplier, getDefaultSupplier, hasDefaultSupplier, hasDefaultSupplier, popOverlay, promoteDefaultsToLocalSuppliers, properties, pushOverlay, registerConfiguration, resolve, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.commons.inject.BeanStore
createBeanFromMethod, getMissingParams, getParams, hasAllParams, instantiate, invokeBeanMethodMethods inherited from interface org.apache.juneau.commons.inject.WritableBeanStore
registerConfigurations
-
Constructor Details
-
SpringBeanStore
Constructor.If
appContextis non-null, this constructor also makes sure the process-wideSettingssingleton holds aSpringEnvironmentPropertySourcefor it, so that@Value("{...}")placeholders resolve against the SpringEnvironment(i.e. againstapplication.yaml, env vars, system properties, etc.). There is one such source per application context, shared by every store built on it and kept at the position of the first registration. It is removed when every store on the context has beencleared, or when the context closes (for aConfigurableApplicationContext).- Parameters:
appContext- The Spring application context used to resolve beans. Can benull (no Spring environment bridge is installed).parent- The parent bean store. Can benull for a root store with no parent chain.
-
-
Method Details
-
clear
Description copied from class:BasicBeanStoreRemoves all beans from this store.This operation only affects this store and does not affect the parent bean store.
- Specified by:
clearin interfaceWritableBeanStore- Overrides:
clearin classBasicBeanStore- Returns:
- This object.
-
invalidateEnvironmentCache
public static boolean invalidateEnvironmentCache(org.springframework.context.ApplicationContext appContext) Clears the miss cache of the SpringEnvironmentbridge registered for the given application context.Needed only after a Spring property source's contents change in place for a key that is not a valid Spring Boot property name and that Juneau already looked up and missed; see
SpringEnvironmentPropertySource.invalidate(). The bridge is shared by everySpringBeanStoreon the context, so this affects all of them.- Parameters:
appContext- The application context. Can benull .- Returns:
true if the context had a registered bridge.- Since:
- 10.0.0
-
getBean
Description copied from class:BasicBeanStoreReturns the unnamed bean of the specified type.If no unnamed bean is found in this store, searches the parent store recursively.
- Specified by:
getBeanin interfaceBeanStore- Overrides:
getBeanin classBasicBeanStore- Type Parameters:
T- The type of bean to return.- Parameters:
beanType- The type of bean to return. Must not benull .- Returns:
- The bean, or
Optional.empty()if not found.
-
getBean
Description copied from class:BasicBeanStoreReturns the named bean of the specified type.If no bean with the specified name is found in this store, searches the parent store recursively.
- Specified by:
getBeanin interfaceBeanStore- Overrides:
getBeanin classBasicBeanStore- Type Parameters:
T- The type of bean to return.- Parameters:
beanType- The type of bean to return. Must not benull .name- The bean name. Can benull for unnamed beans.- Returns:
- The bean, or
Optional.empty()if not found.
-
getBeansOfType
Description copied from class:BasicBeanStoreReturns all beans of the specified type, keyed by bean name.The map keys are the bean names (empty string for unnamed beans), and the values are the bean instances. Results from the parent store are included first, then beans from this store (which override parent beans with the same name).
- Specified by:
getBeansOfTypein interfaceBeanStore- Overrides:
getBeansOfTypein classBasicBeanStore- Type Parameters:
T- The bean type.- Parameters:
beanType- The bean type. Must not benull .- Returns:
- A map of bean names to bean instances. Never
null .
-
hasBean
Description copied from class:BasicBeanStoreReturnstrue if this store contains at least one unnamed bean of the specified type.If not found in this store, searches the parent store recursively.
- Specified by:
hasBeanin interfaceBeanStore- Overrides:
hasBeanin classBasicBeanStore- Parameters:
beanType- The bean type to check. Must not benull .- Returns:
true if this store contains at least one unnamed bean of the specified type.
-
hasBean
Description copied from class:BasicBeanStoreReturnstrue if this store contains a bean of the specified type and name.If not found in this store, searches the parent store recursively.
- Specified by:
hasBeanin interfaceBeanStore- Overrides:
hasBeanin classBasicBeanStore- Parameters:
beanType- The bean type to check. Must not benull .name- The bean name. Can benull for unnamed beans.- Returns:
true if this store contains a bean of the specified type and name.
-
getBeanSupplier
Description copied from class:BasicBeanStoreReturns the supplier for a named bean of the specified type.If no supplier with the specified name is found in this store, searches the parent store recursively.
- Specified by:
getBeanSupplierin interfaceBeanStore- Overrides:
getBeanSupplierin classBasicBeanStore- Type Parameters:
T- The bean type.- Parameters:
beanType- The bean type. Must not benull .name- The bean name. Can benull for unnamed beans.- Returns:
- The supplier, or
Optional.empty()if no supplier of the specified type and name exists.
-