Announcement Announcement Module
Collapse
No announcement yet.
What is the recommended method for setting the JNDI environment on the client ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    If this is a local stateless EJB, you shouldn't need to define the environment. Weblogic should default to the local JVM and WLInitialContextFactory.

    Comment


    • #3
      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, 06:58 AM. Reason: Mistake in original post

      Comment


      • #4
        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.

        Comment


        • #5
          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>

          Comment

          Working...
          X