|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jndi.JndiAccessor org.springframework.jndi.JndiLocatorSupport org.springframework.jndi.JndiObjectLocator org.springframework.jndi.JndiObjectFactoryBean
public class JndiObjectFactoryBean
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
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 lookup 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
DriverManagerDataSource
definition!
setProxyInterface(java.lang.Class)
,
setLookupOnStartup(boolean)
,
setCache(boolean)
,
JndiObjectTargetSource
Field Summary |
---|
Fields inherited from class org.springframework.jndi.JndiLocatorSupport |
---|
CONTAINER_PREFIX |
Fields inherited from class org.springframework.jndi.JndiAccessor |
---|
logger |
Constructor Summary | |
---|---|
JndiObjectFactoryBean()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Look up the JNDI object and store it. |
Object |
getObject()
Return the singleton JNDI object. |
Class |
getObjectType()
Return the type of object that this FactoryBean creates, or null
if not known in advance. |
boolean |
isSingleton()
Is the bean managed by this factory a singleton or a prototype? |
protected Object |
lookupWithFallback()
Lookup variant that that returns the specified "defaultObject" (if any) in case of lookup failure. |
void |
setCache(boolean cache)
Set whether to cache the JNDI object once it has been located. |
void |
setDefaultObject(Object defaultObject)
Specify a default object to fall back to if the JNDI lookup fails. |
void |
setLookupOnStartup(boolean lookupOnStartup)
Set whether to look up the JNDI object on startup. |
void |
setProxyInterface(Class proxyInterface)
Specify the proxy interface to use for the JNDI object. |
Methods inherited from class org.springframework.jndi.JndiObjectLocator |
---|
getExpectedType, getJndiName, lookup, setExpectedType, setJndiName |
Methods inherited from class org.springframework.jndi.JndiLocatorSupport |
---|
convertJndiName, isResourceRef, lookup, lookup, setResourceRef |
Methods inherited from class org.springframework.jndi.JndiAccessor |
---|
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JndiObjectFactoryBean()
Method Detail |
---|
public void setProxyInterface(Class proxyInterface)
Typically used in conjunction with "lookupOnStartup"=false and/or "cache"=false.
setLookupOnStartup(boolean)
,
setCache(boolean)
public void setLookupOnStartup(boolean lookupOnStartup)
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(java.lang.Class)
,
setCache(boolean)
public void setCache(boolean cache)
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.
setProxyInterface(java.lang.Class)
,
setLookupOnStartup(boolean)
public void setDefaultObject(Object defaultObject)
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.
setLookupOnStartup(boolean)
public void afterPropertiesSet() throws IllegalArgumentException, NamingException
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class JndiObjectLocator
IllegalArgumentException
NamingException
protected Object lookupWithFallback() throws NamingException
NamingException
- in case of lookup failure without fallbacksetDefaultObject(java.lang.Object)
public Object getObject()
getObject
in interface FactoryBean
null
;
a null
value will be considered as an indication of
incomplete initialization)FactoryBeanNotInitializedException
public Class getObjectType()
FactoryBean
null
if not known in advance. This allows to check for specific types
of beans without instantiating objects, for example on autowiring.
For a singleton, this 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
null
here. Therefore it is highly recommended to implement
this method properly, using the current state of the FactoryBean.
getObjectType
in interface FactoryBean
null
if not known at the time of the callListableBeanFactory.getBeansOfType(java.lang.Class)
public boolean isSingleton()
FactoryBean
getObject()
always return the same object
(a reference that can be cached)?
NOTE: If a FactoryBean indicates to hold a singleton object,
the object returned from getObject()
might get cached
by the owning BeanFactory. Hence, do not return true
unless the FactoryBean always exposes the same reference.
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
isSingleton
in interface FactoryBean
FactoryBean.getObject()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |