JndiPropertySource (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.jndi

## Class JndiPropertySource

- java.lang.Object
- - org.springframework.core.env.PropertySource<JndiLocatorDelegate>
  - - org.springframework.jndi.JndiPropertySource

-     public class JndiPropertySource
      extends PropertySource<JndiLocatorDelegate>

  `PropertySource` implementation that reads properties from an underlying Spring `JndiLocatorDelegate`.

  By default, the underlying `JndiLocatorDelegate` will be configured with its `"resourceRef"` property set to `true`, meaning that names looked up will automatically be prefixed with "java:comp/env/" in alignment with published JNDI naming conventions. To override this setting or to change the prefix, manually configure a `JndiLocatorDelegate` and provide it to one of the constructors here that accepts it. The same applies when providing custom JNDI properties. These should be specified using `JndiAccessor.setJndiEnvironment(java.util.Properties)` prior to construction of the `JndiPropertySource`.

  Note that `StandardServletEnvironment` includes a `JndiPropertySource` by default, and any customization of the underlying `JndiLocatorDelegate` may be performed within an `ApplicationContextInitializer` or `WebApplicationInitializer`.

  Since:
    3.1
  Author:
    Chris Beams, Juergen Hoeller
  See Also:
    `JndiLocatorDelegate`, `ApplicationContextInitializer`, `WebApplicationInitializer`, `StandardServletEnvironment`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource

      `PropertySource.StubPropertySource`

  - ### Field Summary

    - ### Fields inherited from class org.springframework.core.env.PropertySource

      `logger, name, source`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JndiPropertySource(String name)` Create a new `JndiPropertySource` with the given name and a `JndiLocatorDelegate` configured to prefix any names with "java:comp/env/".
    `JndiPropertySource(String name, JndiLocatorDelegate jndiLocator)` Create a new `JndiPropertySource` with the given name and the given `JndiLocatorDelegate`.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `getProperty(String name)` Return the value associated with the given name, `null` if not found.

    - ### Methods inherited from class org.springframework.core.env.PropertySource

      `containsProperty, equals, getName, getSource, hashCode, named, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### JndiPropertySource

          public JndiPropertySource(String name)

      Create a new `JndiPropertySource` with the given name and a `JndiLocatorDelegate` configured to prefix any names with "java:comp/env/".

    - #### JndiPropertySource

          public JndiPropertySource(String name,
                            JndiLocatorDelegate jndiLocator)

      Create a new `JndiPropertySource` with the given name and the given `JndiLocatorDelegate`.

  - ### Method Detail

    - #### getProperty

          public Object getProperty(String name)

      Return the value associated with the given name, `null` if not found.

      This implementation looks up and returns the value associated with the given name from the underlying `JndiLocatorDelegate`. If a `NamingException` is thrown during the call to `JndiLocatorDelegate.lookup(String)`, returns `null` and issues a DEBUG-level log statement with the exception message.

      Specified by:
        `getProperty` in class `PropertySource<JndiLocatorDelegate>`
      Parameters:
        `name` - the property to find
      See Also:
        `PropertyResolver.getRequiredProperty(String)`