210.4. DirContext

URI ldap:ldapserver は、ID ldapserver を持つ Spring Bean を参照します。ldapserver Bean は次のように定義できます。

<bean id="ldapserver" class="javax.naming.directory.InitialDirContext" scope="prototype">
  <constructor-arg>
    <props>
      <prop key="java.naming.factory.initial">com.sun.jndi.ldap.LdapCtxFactory</prop>
      <prop key="java.naming.provider.url">ldap://localhost:10389</prop>
      <prop key="java.naming.security.authentication">none</prop>
    </props>
  </constructor-arg>
</bean>

前の例では、ローカルでホストされている LDAP サーバーに匿名で接続する通常の Sun ベースの LDAP DirContext を宣言しています。

注記

DirContext オブジェクトは、コントラクトによる同時実行をサポートする必要は ありません。したがって、Bean 定義で scope="prototype" を設定してディレクトリーコンテキストを宣言するか、コンテキストが同時実行をサポートすることが重要です。Spring フレームワークでは、prototype スコープのオブジェクトは、ルックアップされるたびにインスタンス化されます。