public class SimpleJndiBeanFactory extends JndiLocatorSupport implements org.springframework.beans.factory.BeanFactory
BeanFactory
interface.
Does not support enumerating bean definitions, hence doesn't implement
the ListableBeanFactory
interface.
This factory resolves given bean names as JNDI names within the
J2EE 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
CommonAnnotationBeanPostProcessor
,
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.
DefaultListableBeanFactory
,
CommonAnnotationBeanPostProcessor
CONTAINER_PREFIX
logger
Constructor and Description |
---|
SimpleJndiBeanFactory() |
Modifier and Type | Method and Description |
---|---|
void |
addShareableResource(String shareableResource)
Add the name of a shareable JNDI resource,
which this factory is allowed to cache once obtained.
|
boolean |
containsBean(String name) |
String[] |
getAliases(String name) |
<T> T |
getBean(Class<T> requiredType) |
Object |
getBean(String name) |
<T> T |
getBean(String name,
Class<T> requiredType) |
Object |
getBean(String name,
Object... args) |
Class<?> |
getType(String name) |
boolean |
isPrototype(String name) |
boolean |
isSingleton(String name) |
boolean |
isTypeMatch(String name,
Class targetType) |
void |
setShareableResources(String[] shareableResources)
Set a list of names of shareable JNDI resources,
which this factory is allowed to cache once obtained.
|
convertJndiName, isResourceRef, lookup, lookup, setResourceRef
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate
public void setShareableResources(String[] shareableResources)
shareableResources
- the JNDI names
(typically within the "java:comp/env/" namespace)public void addShareableResource(String shareableResource)
shareableResource
- the JNDI name
(typically within the "java:comp/env/" namespace)public Object getBean(String name) throws org.springframework.beans.BeansException
getBean
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.BeansException
public <T> T getBean(String name, Class<T> requiredType) throws org.springframework.beans.BeansException
getBean
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.BeansException
public <T> T getBean(Class<T> requiredType) throws org.springframework.beans.BeansException
getBean
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.BeansException
public Object getBean(String name, Object... args) throws org.springframework.beans.BeansException
getBean
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.BeansException
public boolean containsBean(String name)
containsBean
in interface org.springframework.beans.factory.BeanFactory
public boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
isSingleton
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.factory.NoSuchBeanDefinitionException
public boolean isPrototype(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
isPrototype
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.factory.NoSuchBeanDefinitionException
public boolean isTypeMatch(String name, Class targetType) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
isTypeMatch
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.factory.NoSuchBeanDefinitionException
public Class<?> getType(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
getType
in interface org.springframework.beans.factory.BeanFactory
org.springframework.beans.factory.NoSuchBeanDefinitionException