org.springframework.beans.factory.BeanFactory interface.
Does not support enumerating bean definitions, hence doesn't implement
the org.springframework.beans.factory.ListableBeanFactory interface.
This factory resolves given bean names as JNDI names within the
Jakarta EE application's "java:comp/env/" namespace. It caches the resolved
types for all obtained objects, and optionally also caches shareable
objects (if they are explicitly marked as
shareable resource).
The main intent of this factory is usage in combination with Spring's
org.,
configured as "resourceFactory" for resolving @Resource
annotations as JNDI objects without intermediate bean definitions.
It may be used for similar lookup scenarios as well, of course,
in particular if BeanFactory-style type checking is required.
org.springframework.beans.factory.support.DefaultListableBeanFactory , org.springframework.context.annotation.CommonAnnotationBeanPostProcessor
| Modifier and Type | Field and Description |
|---|---|
| private final Map | resourceTypes
Cache of the types of nonshareable resources: bean name to bean type. |
| private final Set | shareableResources
JNDI names of resources that are known to be shareable, i.e. can be cached |
| private final Map | singletonObjects
Cache of shareable singleton objects: bean name to bean instance. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addShareableResource(String
the JNDI name
(typically within the "java:comp/env/" namespace) shareableResource)Add the name of a shareable JNDI resource, which this factory is allowed to cache once obtained. |
| public boolean | containsBean(String
the name of the bean to query name)Implements org. Does this bean factory contain a bean definition or externally registered singleton instance with the given name? |
| private <T> T | |
| private Class | |
| public String[] | getAliases(String
the bean name to check for aliases name)Implements org. Return the aliases for the given bean name, if any. |
| public Object | getBean(String
the name of the bean to retrieve name)Implements org. Return an instance, which may be shared or independent, of the specified bean. |
| public <T> T | getBean(String
the name of the bean to retrieve name, Class<T> type the bean must match; can be an interface or superclass requiredType)Implements org. Return an instance, which may be shared or independent, of the specified bean. |
| public Object | getBean(String
the name of the bean to retrieve name, Object... arguments to use when creating a bean instance using explicit arguments
(only applied when creating a new instance as opposed to retrieving an existing one) args)Implements org. Return an instance, which may be shared or independent, of the specified bean. |
| public <T> T | getBean(Class<T>
type the bean must match; can be an interface or superclass requiredType)Implements org. Return the bean instance that uniquely matches the given object type, if any. |
| public <T> T | getBean(Class<T>
type the bean must match; can be an interface or superclass requiredType, Object... arguments to use when creating a bean instance using explicit arguments
(only applied when creating a new instance as opposed to retrieving an existing one) args)Implements org. Return an instance, which may be shared or independent, of the specified bean. |
| public <T> ObjectProvider | getBeanProvider(Class<T>
type the bean must match; can be an interface or superclass requiredType)Implements org. Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options. |
| public <T> ObjectProvider | getBeanProvider(ResolvableType
type the bean must match; can be a generic type declaration requiredType)Implements org. Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options. |
| public Class | getType(String
the name of the bean to query name)Implements org. Determine the type of the bean with the given name. |
| public Class | getType(String
the name of the bean to query name, boolean whether a allowFactoryBeanInit)FactoryBean may get initialized
just for the purpose of determining its object typeImplements org. Determine the type of the bean with the given name. |
| public boolean | isPrototype(String
the name of the bean to query name)Implements org. Is this bean a prototype? |
| public boolean | isSingleton(String
the name of the bean to query name)Implements org. Is this bean a shared singleton? |
| public boolean | isTypeMatch(String
the name of the bean to query name, ResolvableType the type to match against (as a typeToMatch)ResolvableType)Implements org. Check whether the bean with the given name matches the specified type. |
| public boolean | isTypeMatch(String
the name of the bean to query name, Class<?> the type to match against (as a typeToMatch)Class)Implements org. Check whether the bean with the given name matches the specified type. |
| public void | setShareableResources(String...
the JNDI names
(typically within the "java:comp/env/" namespace) shareableResources)Set a list of names of shareable JNDI resources, which this factory is allowed to cache once obtained. |
| resourceTypes | back to summary |
|---|---|
| private final Map<String, Class<?>> resourceTypes Cache of the types of nonshareable resources: bean name to bean type. | |
| shareableResources | back to summary |
|---|---|
| private final Set<String> shareableResources JNDI names of resources that are known to be shareable, i.e. can be cached | |
| singletonObjects | back to summary |
|---|---|
| private final Map<String, Object> singletonObjects Cache of shareable singleton objects: bean name to bean instance. | |
| SimpleJndiBeanFactory | back to summary |
|---|---|
| public SimpleJndiBeanFactory() | |
| addShareableResource | back to summary |
|---|---|
| public void addShareableResource(String shareableResource) Add the name of a shareable JNDI resource, which this factory is allowed to cache once obtained.
| |
| containsBean | back to summary |
|---|---|
| public boolean containsBean(String name) Implements org. Doc from org. Does this bean factory contain a bean definition or externally registered singleton instance with the given name? If the given name is an alias, it will be translated back to the corresponding canonical bean name. If this factory is hierarchical, will ask any parent factory if the bean cannot be found in this factory instance. If a bean definition or singleton instance matching the given name is found,
this method will return | |
| doGetSingleton | back to summary |
|---|---|
private <T> T doGetSingleton(String name, Class<T> requiredType) throws NamingException
| |
| doGetType | back to summary |
|---|---|
| private Class | |
| getAliases | back to summary |
|---|---|
| public String[] getAliases(String name) Implements org. Doc from org. Return the aliases for the given bean name, if any. All of those aliases point to the same bean when used in a If the given name is an alias, the corresponding original bean name and other aliases (if any) will be returned, with the original bean name being the first element in the array. Will ask the parent factory if the bean cannot be found in this factory instance. | |
| getBean | back to summary |
|---|---|
| public Object getBean(String name) throws BeansException Implements org. Doc from org. Return an instance, which may be shared or independent, of the specified bean. This method allows a Spring BeanFactory to be used as a replacement for the Singleton or Prototype design pattern. Callers may retain references to returned objects in the case of Singleton beans. Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| getBean | back to summary |
|---|---|
| public <T> T getBean(String name, Class<T> requiredType) throws BeansException Implements org. Doc from org. Return an instance, which may be shared or independent, of the specified bean. Behaves the same as Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| getBean | back to summary |
|---|---|
| public Object getBean(String name, Object... args) throws BeansException Implements org. Doc from org. Return an instance, which may be shared or independent, of the specified bean. Allows for specifying explicit constructor arguments / factory method arguments, overriding the specified default arguments (if any) in the bean definition. Note that the provided arguments need to match a specific candidate constructor / factory method in the order of declared parameters.
| |
| getBean | back to summary |
|---|---|
| public <T> T getBean(Class<T> requiredType) throws BeansException Implements org. Doc from org. Return the bean instance that uniquely matches the given object type, if any. This method goes into
| |
| getBean | back to summary |
|---|---|
| public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException Implements org. Doc from org. Return an instance, which may be shared or independent, of the specified bean. Allows for specifying explicit constructor arguments / factory method arguments, overriding the specified default arguments (if any) in the bean definition. Note that the provided arguments need to match a specific candidate constructor / factory method in the order of declared parameters. This method goes into
| |
| getBeanProvider | back to summary |
|---|---|
| public <T> ObjectProvider Implements org. Doc from org. Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options. For matching a generic type, consider
| |
| getBeanProvider | back to summary |
|---|---|
| public <T> ObjectProvider Implements org. Doc from org. Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options. This variant allows for specifying a generic type to match, similar to reflective injection points with generic type declarations in method/constructor parameters. Note that collections of beans are not supported here, in contrast to reflective
injection points. For programmatically retrieving a list of beans matching a
specific type, specify the actual bean type as an argument here and subsequently
use Also, generics matching is strict here, as per the Java assignment rules.
For lenient fallback matching with unchecked semantics (similar to the ´unchecked´
Java compiler warning), consider calling
| |
| getType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Determine the type of the bean with the given name. More specifically,
determine the type of object that For a Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| getType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Determine the type of the bean with the given name. More specifically,
determine the type of object that For a Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| isPrototype | back to summary |
|---|---|
| public boolean isPrototype(String name) throws NoSuchBeanDefinitionException Implements org. Doc from org. Is this bean a prototype? That is, will Note This method returning Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton(String name) throws NoSuchBeanDefinitionException Implements org. Doc from org. Is this bean a shared singleton? That is, will Note This method returning Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| isTypeMatch | back to summary |
|---|---|
| public boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException Implements org. Doc from org. Check whether the bean with the given name matches the specified type.
More specifically, check whether a Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| isTypeMatch | back to summary |
|---|---|
| public boolean isTypeMatch(String name, Class<?> typeToMatch) throws NoSuchBeanDefinitionException Implements org. Doc from org. Check whether the bean with the given name matches the specified type.
More specifically, check whether a Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.
| |
| setShareableResources | back to summary |
|---|---|
| public void setShareableResources(String... shareableResources) Set a list of names of shareable JNDI resources, which this factory is allowed to cache once obtained.
| |