|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.jndi.JndiAccessor
org.springframework.jndi.JndiLocatorSupport
org.springframework.jndi.JndiObjectLocator
org.springframework.jndi.JndiObjectFactoryBean
FactoryBean that looks up a JNDI object. Behaves like the object when used as bean reference, e.g. for JdbcTemplate's dataSource property.
The typical usage will be to register this as singleton factory (e.g. for a certain JNDI DataSource) in an application context, and give bean references to application services that need it.
Assumptions: The resource obtained from JNDI is available at context startup time and can be cached. If this is not the case, consider using a ProxyFactoryBean with JndiObjectTargetSource, which fetches objects from JNDI on demand.
Of course, service implementations can lookup e.g. a DataSource from JNDI themselves, but this class enables central configuration of the JNDI name, and easy switching to non-JNDI replacements. The latter can be used for test setups, standalone clients, etc.
Note that switching to e.g. DriverManagerDataSource is just a matter of configuration: replace the definition of this FactoryBean with a DriverManagerDataSource definition!
JndiObjectTargetSource
,
JdbcAccessor.setDataSource(javax.sql.DataSource)
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. |
java.lang.Object |
getObject()
Return the singleton JNDI object. |
java.lang.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? |
Methods inherited from class org.springframework.jndi.JndiObjectLocator |
getJndiName, lookup, setJndiName |
Methods inherited from class org.springframework.jndi.JndiLocatorSupport |
convertJndiName, isResourceRef, 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 afterPropertiesSet() throws javax.naming.NamingException
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class JndiObjectLocator
javax.naming.NamingException
JndiObjectLocator.lookup()
public java.lang.Object getObject()
getObject
in interface FactoryBean
public java.lang.Class getObjectType()
FactoryBean
For a singleton, this can simply return getObject().getClass(), or even null, as autowiring will always check the actual objects for singletons. For prototypes, returning a meaningful type here is highly advisable, as autowiring will simply ignore them else.
getObjectType
in interface FactoryBean
ListableBeanFactory.getBeansOfType(java.lang.Class, boolean, boolean)
public boolean isSingleton()
FactoryBean
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory.
isSingleton
in interface FactoryBean
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |