org.springframework.jndi

## 类 JndiObjectFactoryBean

- java.lang.Object
- - org.springframework.jndi.JndiAccessor
  - - org.springframework.jndi.JndiLocatorSupport
    - - org.springframework.jndi.JndiObjectLocator
      - - org.springframework.jndi.JndiObjectFactoryBean

- 所有已实现的接口:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanClassLoaderAware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.FactoryBean<Object>, org.springframework.beans.factory.InitializingBean

      public class JndiObjectFactoryBean
      extends JndiObjectLocator
      implements org.springframework.beans.factory.FactoryBean<Object>, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanClassLoaderAware

  `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 `org.springframework.jdbc.datasource.DriverManagerDataSource` definition!

  从以下版本开始:
    22.05.2003
  作者:
    Juergen Hoeller
  另请参阅:
    `setProxyInterface(java.lang.Class<?>)`, `setLookupOnStartup(boolean)`, `setCache(boolean)`, `JndiObjectTargetSource`

- - ### 字段概要

    - ### 从类继承的字段 org.springframework.jndi.JndiLocatorSupport

      `CONTAINER_PREFIX`

    - ### 从类继承的字段 org.springframework.jndi.JndiAccessor

      `logger`

  - ### 构造器概要

    构造器
    构造器和说明
    `JndiObjectFactoryBean()`

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `afterPropertiesSet()` Look up the JNDI object and store it.
    `protected Class<?>` | `createCompositeInterface(Class<?>[] interfaces)` Create a composite interface Class for the given interfaces, implementing the given interfaces in one single Class.
    `Object` | `getObject()` Return the singleton JNDI object.
    `Class<?>` | `getObjectType()`
    `boolean` | `isSingleton()`
    `protected Object` | `lookupWithFallback()` Lookup variant that returns the specified "defaultObject" (if any) in case of lookup failure.
    `void` | `setBeanClassLoader(ClassLoader classLoader)`
    `void` | `setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)`
    `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` | `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.
    `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.
    `void` | `setProxyInterfaces(Class<?>... proxyInterfaces)` Specify multiple proxy interfaces to use for the JNDI object.

    - ### 从类继承的方法 org.springframework.jndi.JndiObjectLocator

      `getExpectedType, getJndiName, lookup, setExpectedType, setJndiName`

    - ### 从类继承的方法 org.springframework.jndi.JndiLocatorSupport

      `convertJndiName, isResourceRef, lookup, lookup, setResourceRef`

    - ### 从类继承的方法 org.springframework.jndi.JndiAccessor

      `getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### JndiObjectFactoryBean

          public JndiObjectFactoryBean()

  - ### 方法详细资料

    - #### setProxyInterface

          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(java.lang.Class<?>...)`, `setLookupOnStartup(boolean)`, `setCache(boolean)`

    - #### setProxyInterfaces

          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.

      另请参阅:
        `JndiObjectLocator.setExpectedType(java.lang.Class<?>)`, `setLookupOnStartup(boolean)`, `setCache(boolean)`

    - #### setLookupOnStartup

          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(java.lang.Class<?>)`, `setCache(boolean)`

    - #### setCache

          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.

      另请参阅:
        `setProxyInterface(java.lang.Class<?>)`, `setLookupOnStartup(boolean)`

    - #### setExposeAccessContext

          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.

    - #### setDefaultObject

          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 `JndiObjectLocator.setExpectedType(java.lang.Class<?>)`, the specified value needs to be either of that type or convertible to it.

      另请参阅:
        `setLookupOnStartup(boolean)`, `ConfigurableBeanFactory.getTypeConverter()`, `SimpleTypeConverter`

    - #### setBeanFactory

          public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)

      指定者:
        `setBeanFactory` 在接口中 `org.springframework.beans.factory.BeanFactoryAware`

    - #### setBeanClassLoader

          public void setBeanClassLoader(ClassLoader classLoader)

      指定者:
        `setBeanClassLoader` 在接口中 `org.springframework.beans.factory.BeanClassLoaderAware`

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws IllegalArgumentException,
                                         NamingException

      Look up the JNDI object and store it.
      指定者:
        `afterPropertiesSet` 在接口中 `org.springframework.beans.factory.InitializingBean`
      覆盖:
        `afterPropertiesSet` 在类中 `JndiObjectLocator`
      抛出:
        `IllegalArgumentException`
        `NamingException`

    - #### lookupWithFallback

          protected Object lookupWithFallback()
                                       throws NamingException

      Lookup variant that returns the specified "defaultObject" (if any) in case of lookup failure.
      返回:
        the located object, or the "defaultObject" as fallback
      抛出:
        `NamingException` - in case of lookup failure without fallback
      另请参阅:
        `setDefaultObject(java.lang.Object)`

    - #### getObject

          @Nullable
          public Object getObject()

      Return the singleton JNDI object.
      指定者:
        `getObject` 在接口中 `org.springframework.beans.factory.FactoryBean<Object>`

    - #### getObjectType

          public Class<?> getObjectType()

      指定者:
        `getObjectType` 在接口中 `org.springframework.beans.factory.FactoryBean<Object>`

    - #### isSingleton

          public boolean isSingleton()

      指定者:
        `isSingleton` 在接口中 `org.springframework.beans.factory.FactoryBean<Object>`

    - #### createCompositeInterface

          protected Class<?> createCompositeInterface(Class<?>[] interfaces)

      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.

      参数:
        `interfaces` - the interfaces to merge
      返回:
        the merged interface as Class
      另请参阅:
        `Proxy.getProxyClass(java.lang.ClassLoader, java.lang.Class<?>...)`