Results 1 to 5 of 5

Thread: What is the recommended method for setting the JNDI environment on the client ?

  1. #1
    Join Date
    Oct 2005
    Location
    Munich
    Posts
    4

    Default What is the recommended method for setting the JNDI environment on the client ?

    Hello all,

    I'm new to spring, so forgive the basic question, but I can't find the answer in either of the books on my desk, or in google.

    I have a basic "Hello World" SLSB EJB which I am testing a simple client. The client contains the horrible code:

    Code:
    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
        weblogic.jndi.T3InitialContextFactory");
    p.put(Context.PROVIDER_URL, url);
    return new InitialContext(p);
    Using Spring, I still want to get these JNDI properties (the factory and the URL) into my application to tell it to use my JNDI. No clues from the books, but I finally figured to create a JndiTemplate and set autowire on the bean defining the SLSB proxy.

    Code:
    <bean id="helloWorld" autowire="byName"
    class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean">
    ... etc ...
    
    <bean id="jndiTemplate"
    class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
    <props>
    <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory </prop>
    <prop key="java.naming.provider.url">t3://localhost:7001</prop>
    </props>
    </property>
    </bean>
    What I am wondering is, is this the correct approach, or is there some way of setting the "default" JndiTemplate in the framework and avoiding injecting the template into each bean using autowire (or maybe a different method).

    thanks

    Richard

  2. #2
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    If this is a local stateless EJB, you shouldn't need to define the environment. Weblogic should default to the local JVM and WLInitialContextFactory.
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  3. #3
    Join Date
    Oct 2005
    Location
    Munich
    Posts
    4

    Default

    It is a remote session bean. The caller is any Java client, not necessarily running on a system with WebLogic, although in this case it is.

    OK - I noticed a mistake in the original post: I used a Local proxy instead of a Remote proxy. I've fixed that, but I still need to provide the JNDI environment, so I think the question still stands.

    Basically, I was wondering what is the "best practice" for initialising the JNDI environment in a remote client.
    Last edited by planet; Oct 24th, 2005 at 06:58 AM. Reason: Mistake in original post

  4. #4
    Join Date
    Aug 2004
    Location
    New York
    Posts
    168

    Default

    I think Defining one JndiTemplate with all of your properties is a clean approach. This JndiTemplate can then be injected into all of your JndiObjectFactoryBean objects.
    Karl Baum
    weblog: www.jroller.com/page/kbaum

  5. #5
    Join Date
    Oct 2005
    Location
    Boston
    Posts
    1

    Default

    I can think of two other ways to do this:
    1) Use a PropertiesFactoryBean to inject the properties into other beans
    Code:
    <bean id="jndiProperties" value="org.springframework.beans.factory.config.PropertiesFactoryBean">
      <property name="properties">
        <props>
          <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory </prop>
          <prop key="java.naming.provider.url">t3://localhost:7001</prop>
        </props>
      </property>
    </bean>
    
    <bean id="helloWorld" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
      <property name="jndiEnvironment"><ref bean="jndiProperties" /></property>
      ...
    </bean>
    2) Use an abstract bean definition
    Code:
    <bean id="jndiAccessor" abstract="true">
      <property name="jndiEnvironment">
        <props>
          <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory </prop>
          <prop key="java.naming.provider.url">t3://localhost:7001</prop>
        </props>
      </property>
    </bean>
    
    <bean id="helloWorld" parent="jndiAccessor" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean">
      ...
    </bean>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •