Announcement Announcement Module
Collapse
No announcement yet.
Configuring Initial Context Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring Initial Context

    Hi,
    I am new to Spring . Will u please help me to set the Initila Context to look up a session bean . I am using EJB 2.x and Jboss 4.0.4

    Please help

  • #2
    Hi Anupam,

    One way of doing things is that .. ( assuming deployment is available on local server )

    Code:
    <bean id="demoLookup"
    			class="org.springframework.jndi.JndiObjectFactoryBean">
    			<property name="cache" value="true" />
    			<property name="lookupOnStartup" value="true" />
    			<property name="proxyInterface" value="your fully qualified look up business interface" />
    			<property name="jndiName" >
    				<value>contextName/ejbName/remote or local </value>  // assuming you have not over ridden the default naming strategy.
    			</property>
    			<property name="jndiEnvironment">
    			     <props>
    			       <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
    			       <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
    			       <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
    			     </props>
    		   </property>
    		</bean>
    wire in this bean demoLookup to your other required bean.

    Hope this helps.

    Comment


    • #3
      Originally posted by vasudm82 View Post
      Hi Anupam,

      One way of doing things is that .. ( assuming deployment is available on local server )

      Code:
      <bean id="demoLookup"
      			class="org.springframework.jndi.JndiObjectFactoryBean">
      			<property name="cache" value="true" />
      			<property name="lookupOnStartup" value="true" />
      			<property name="proxyInterface" value="your fully qualified look up business interface" />
      			<property name="jndiName" >
      				<value>contextName/ejbName/remote or local </value>  // assuming you have not over ridden the default naming strategy.
      			</property>
      			<property name="jndiEnvironment">
      			     <props>
      			       <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
      			       <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
      			       <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
      			     </props>
      		   </property>
      		</bean>
      wire in this bean demoLookup to your other required bean.

      Hope this helps.


      thanks a lot . This is working fine. I have a project in which Session Bean Calls Entity Bean. And this Session beans functions are exposed to Remote Client.

      Now i am planning to convert this to Spring + Hibernate .. Will u please tell me wat is the best way to do this ? I want to expose the Functionality to Remote User Like earlier i used to do.

      Thanks a Lot in advance...

      Comment


      • #4
        Hi Anupam,

        I am not sure whether i got your question properly .

        Do you want to use hibernate instead of entity bean in session bean
        or
        Do you want to inject spring beans ( proxy factory bean having the hibernate integration ) into session bean?


        assuming the later is your question, Please go through chapter 18 in the Spring reference material.

        Hope this helps.
        Last edited by vasudm82; Sep 25th, 2008, 07:41 AM. Reason: session is changed to session bean.

        Comment


        • #5
          Originally posted by vasudm82 View Post
          Hi Anupam,

          I am not sure whether i got your question properly .

          Do you want to use hibernate instead of entity bean in session bean
          or
          Do you want to inject spring beans ( proxy factory bean having the hibernate integration ) into session bean?


          assuming the later is your question, Please go through chapter 18 in the Spring reference material.

          Hope this helps.


          Chapter 18 of which book ? Will u please give me the reference or Link ?

          Comment


          • #6
            Originally posted by anupamkakade View Post
            Chapter 18 of which book ? Will u please give me the reference or Link ?
            This is not as simple as you are trying to make it. He is referring to the spring documentation itself. There are chapters on each topic: EJB integration, remoting, hibernate integration. There are also other threads in this section and others detailing each step of your proposed high-level architecture. IMO if you need remoting and already have EJB's you should use them and then manage the EJB's in spring. Changing it to hibernate is a whole other story, especially for remote EJB's. Where do you create spring context then? Where do you create hibernate sessions then? If you are looking for some canned solution to your problem you are absolutely not going to find it. Such a solution is very much dependent on your own trial and error and having an actual understanding of the components and what functionality they provide -- I don't think you'll be able to get by by cutting and pasting small portions of the overall solution from forums. Also, you double-posted the exact same post... seems ill-advised.

            Comment


            • #7
              Originally posted by reganjeremy View Post
              This is not as simple as you are trying to make it. He is referring to the spring documentation itself. There are chapters on each topic: EJB integration, remoting, hibernate integration. There are also other threads in this section and others detailing each step of your proposed high-level architecture. IMO if you need remoting and already have EJB's you should use them and then manage the EJB's in spring. Changing it to hibernate is a whole other story, especially for remote EJB's. Where do you create spring context then? Where do you create hibernate sessions then? If you are looking for some canned solution to your problem you are absolutely not going to find it. Such a solution is very much dependent on your own trial and error and having an actual understanding of the components and what functionality they provide -- I don't think you'll be able to get by by cutting and pasting small portions of the overall solution from forums. Also, you double-posted the exact same post... seems ill-advised.


              Thanks a lot. But try to undersatand my requirement . Will it be possible thru Spring + Hibernate ?

              Comment


              • #8
                Thanks a lot. But try to undersatand my requirement . Will it be possible thru Spring + Hibernate ?
                The idea came to my mind because i read somewhere that As a lightweight container, Spring is often considered an EJB replacement.

                Comment


                • #9
                  I believe it is possible but it may not be. You will have to have the same JNDI datasource configured in your remote container though and then use ContextSingletonBeanFactoryLocator. I am not sure how to create the hibernate session factory then though. In the remote bean, you may have to configure the hibernate session factory only when the remote EJB service method is invoked. you could also maybe do it when that remote EJB has been set up in the spring remote EJB way, and then do it in the ejb create method or setcontext. It is tricky because of your remote requirement. In the spring docs, it says, use Spring as replacement for EJB insofar as you would not gain anything by using the remote features. Since you do, it may be more trouble than it's worth. If you use it as a remote EJB you may suffer the penalty of having to reconfigure the hibernate session factory each remote service call invocation.. only way to do it is to try it out. In my experience I have only used JNDI datasource injected and then use JDBC template in stead of hibernate. In others, I have used only spring and hibernate without EJB.

                  Comment


                  • #10
                    * configure spring context in servlet context
                    * have a POJO service injected with the remote EJB

                    ( see http://static.springframework.org/sp...-access-remote

                    and

                    http://forum.springframework.org/showthread.php?t=59184)

                    * remote EJB must be loaded in a container in which beanRefContext.xml is in the classpath so that one of the various bean factory locators can be used. I have only ever used ContextSingletonBeanFactoryLocator but it works great.

                    * That beanRefContext.xml will have ref to other bean definition file that you will tell that remote EJB to use in the set context method as per the chapter 18 stuff.

                    * in that bean def, configure your hibernate session factory as normal for a spring hibernate session factory configuration.

                    see http://static.springframework.org/sp...-factory-setup

                    * the problem is, if you have some local and some remote, consider concurrent updates problems, transaction demarcation, distributed data issues. I believe these problems are what entity EJB's are meant to solve.

                    That's the limit of my knowledge and experience. Best of luck.

                    Comment

                    Working...
                    X