org.springframework.beans.factory.FactoryBean that looks up a
JNDI object. Exposes the object found in JNDI for bean references,
e.g. for data access object's "dataSource" property in case of a
javax.sql.DataSource .
The typical usage will be to register this as singleton factory (e.g. for a certain JNDI-bound DataSource) in an application context, and give bean references to application services that need it.
The default behavior is to look up the JNDI object on startup and cache it.
This can be customized through the "lookupOnStartup" and "cache" properties,
using a JndiObjectTargetSource underneath. Note that you need to specify
a "proxyInterface" in such a scenario, since the actual JNDI object type is not
known in advance.
Of course, bean classes in a Spring environment may look up e.g. a DataSource from JNDI themselves. This class simply enables central configuration of the JNDI name, and easy switching to non-JNDI alternatives. The latter is particularly convenient for test setups, reuse in standalone clients, etc.
Note that switching to e.g. DriverManagerDataSource is just a matter of
configuration: Simply replace the definition of this FactoryBean with a
org. definition!
setProxyInterface, setLookupOnStartup, setCache, JndiObjectTargetSource
| Modifier and Type | Class and Description |
|---|---|
| private static class | JndiObjectFactoryBean.
Interceptor that exposes the JNDI context for all method invocations, according to JndiObjectFactoryBean's "exposeAccessContext" flag. |
| private static class | JndiObjectFactoryBean.
Inner class to just introduce an AOP dependency when actually creating a proxy. |
| Modifier and Type | Field and Description |
|---|---|
| private ClassLoader | |
| private ConfigurableBeanFactory | |
| private boolean | |
| private Object | |
| private boolean | |
| private Object | |
| private boolean | |
| private Class |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Overrides org. Implements org. Look up the JNDI object and store it. |
| protected Class | Returns: the merged interface as Classthe interfaces to merge interfaces)Create a composite interface Class for the given interfaces, implementing the given interfaces in one single Class. |
| public Object | getObject()
Implements org. Return the singleton JNDI object. |
| public Class | getObjectType()
Implements org. Return the type of object that this FactoryBean creates,
or |
| public boolean | isSingleton()
Overrides default org. Is the object managed by this factory a singleton? |
| protected Object | Returns: the located object, or the "defaultObject" as fallbackLookup variant that returns the specified "defaultObject" (if any) in case of lookup failure. |
| public void | setBeanClassLoader(ClassLoader
the owning class loader classLoader)Implements org. Callback that supplies the bean |
| public void | setBeanFactory(BeanFactory
owning BeanFactory (never beanFactory)null).
The bean can immediately call methods on the factory.Implements org. Callback that supplies the owning factory to a bean instance. |
| public void | |
| public void | setDefaultObject(Object defaultObject)
Specify a default object to fall back to if the JNDI lookup fails. |
| public void | setExposeAccessContext(boolean exposeAccessContext)
Set whether to expose the JNDI environment context for all access to the target object, i.e. for all method invocations on the exposed object reference. |
| public void | |
| public void | |
| public void | setProxyInterfaces(Class<?>... proxyInterfaces)
Specify multiple proxy interfaces to use for the JNDI object. |
| beanClassLoader | back to summary |
|---|---|
| private ClassLoader beanClassLoader
| |
| beanFactory | back to summary |
|---|---|
| private ConfigurableBeanFactory beanFactory
| |
| cache | back to summary |
|---|---|
| private boolean cache | |
| defaultObject | back to summary |
|---|---|
| private Object defaultObject
| |
| exposeAccessContext | back to summary |
|---|---|
| private boolean exposeAccessContext | |
| jndiObject | back to summary |
|---|---|
| private Object jndiObject
| |
| lookupOnStartup | back to summary |
|---|---|
| private boolean lookupOnStartup | |
| proxyInterfaces | back to summary |
|---|---|
| private Class<?>[] proxyInterfaces
| |
| JndiObjectFactoryBean | back to summary |
|---|---|
| public JndiObjectFactoryBean() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() throws IllegalArgumentException, NamingException Overrides org. Implements org. Look up the JNDI object and store it.
| |
| createCompositeInterface | back to summary |
|---|---|
| protected Class Create a composite interface Class for the given interfaces, implementing the given interfaces in one single Class. The default implementation builds a JDK proxy class for the given interfaces.
| |
| getObject | back to summary |
|---|---|
| public Object getObject() Implements org. Return the singleton JNDI object.
| |
| getObjectType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Return the type of object that this FactoryBean creates,
or This allows one to check for specific types of beans without instantiating objects, for example on autowiring. In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too. This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available. Note Autowiring will simply ignore FactoryBeans that return
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| lookupWithFallback | back to summary |
|---|---|
| protected Object lookupWithFallback() throws NamingException Lookup variant that returns the specified "defaultObject" (if any) in case of lookup failure.
| |
| setBeanClassLoader | back to summary |
|---|---|
| public void setBeanClassLoader(ClassLoader classLoader) Implements org. Doc from org. Callback that supplies the bean Invoked after the population of normal bean properties but
before an initialization callback such as
| |
| setBeanFactory | back to summary |
|---|---|
| public void setBeanFactory(BeanFactory beanFactory) Implements org. Doc from org. Callback that supplies the owning factory to a bean instance. Invoked after the population of normal bean properties
but before an initialization callback such as
| |
| setCache | back to summary |
|---|---|
| public void setCache(boolean cache) Set whether to cache the JNDI object once it has been located. Default is "true". Can be turned off to allow for hot redeployment of JNDI objects. In this case, the JNDI object will be fetched for each invocation. For hot redeployment, a proxy interface needs to be specified.
| |
| setDefaultObject | back to summary |
|---|---|
| public void setDefaultObject(Object defaultObject) Specify a default object to fall back to if the JNDI lookup fails. Default is none. This can be an arbitrary bean reference or literal value. It is typically used for literal values in scenarios where the JNDI environment might define specific config settings but those are not required to be present. Note This is only supported for lookup on startup.
If specified together with | |
| setExposeAccessContext | back to summary |
|---|---|
| public void setExposeAccessContext(boolean exposeAccessContext) Set whether to expose the JNDI environment context for all access to the target object, i.e. for all method invocations on the exposed object reference. Default is "false", i.e. to only expose the JNDI context for object lookup. Switch this flag to "true" in order to expose the JNDI environment (including the authorization context) for each method invocation, as needed by WebLogic for JNDI-obtained factories (e.g. JDBC DataSource, JMS ConnectionFactory) with authorization requirements. | |
| setLookupOnStartup | back to summary |
|---|---|
| public void setLookupOnStartup(boolean lookupOnStartup) Set whether to look up the JNDI object on startup. Default is "true". Can be turned off to allow for late availability of the JNDI object. In this case, the JNDI object will be fetched on first access. For a lazy lookup, a proxy interface needs to be specified.
| |
| setProxyInterface | back to summary |
|---|---|
| public void setProxyInterface(Class<?> proxyInterface) Specify the proxy interface to use for the JNDI object. Typically used in conjunction with "lookupOnStartup"=false and/or "cache"=false. Needs to be specified because the actual JNDI object type is not known in advance in case of a lazy lookup.
| |
| setProxyInterfaces | back to summary |
|---|---|
| public void setProxyInterfaces(Class<?>... proxyInterfaces) Specify multiple proxy interfaces to use for the JNDI object. Typically used in conjunction with "lookupOnStartup"=false and/or "cache"=false. Note that proxy interfaces will be autodetected from a specified "expectedType", if necessary.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final JndiTemplate |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | invoke(MethodInvocation
the method invocation joinpoint invocation)Implements org. Implement this method to perform extra treatments before and after the invocation. |
| protected boolean |
| jndiTemplate | back to summary |
|---|---|
| private final JndiTemplate jndiTemplate | |
| JndiContextExposingInterceptor | back to summary |
|---|---|
| public JndiContextExposingInterceptor(JndiTemplate jndiTemplate) | |
| invoke | back to summary |
|---|---|
| public Object invoke(MethodInvocation invocation) throws Throwable Implements org. Doc from org. Implement this method to perform extra treatments before and
after the invocation. Polite implementations would certainly
like to invoke
| |
| isEligible | back to summary |
|---|---|
| protected boolean isEligible(Method method) | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static Object |
| JndiObjectProxyFactory | back to summary |
|---|---|
| private JndiObjectProxyFactory() | |
| createJndiObjectProxy | back to summary |
|---|---|
| private static Object createJndiObjectProxy(JndiObjectFactoryBean jof) throws NamingException | |