Announcement Announcement Module
Collapse
No announcement yet.
Accessing EJB from within another EJB Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing EJB from within another EJB

    In my OC4J, each service is deployed as it's own application. I need to access one service from another, but I don't know how.

    Let's say I want to access service A (in application Aa) from service B (in application Ba). I've tried setting Aa as a shared library and made Ba import Aa. When I use getBean(), the beanRefContext of A is read. It contains a jdbcTemplate bean, Datasource bean and a service impl bean, but I get a noClassDefFoundError on JdbcTemplate.

    I know that the service (in my example, service A) works fine when it is called from the client.

    Any ideas?
    Last edited by richared; Apr 17th, 2007, 01:34 AM.

  • #2
    You could use SimpleRemoteStatelessSessionProxyFactoryBean to refer to the external service.

    Regards,
    Andreas

    Comment


    • #3
      Hi. Thanks for your answer.

      I use a SRSSPFB on the service to access the other service. And it seems to connect, because Spring starts parsing the beanRefContext file on the service I try to access, but somehow, it fails to recognize JdbcTemplate. Is it possible that since I access a service from another service, that the shared libraries are not properly loaded into the ClassLoader? That is strange as well, since it is apparent that the BeanFactory class is found since it starts parsing the beanRef.

      Comment


      • #4
        So do I understand you correctly that the second service fails to initialize? That means you cannot access it from anywhere else, too?

        Comment


        • #5
          No the service works fine when instanciated from the client, but it fails to load properly when called from another service within the same container.

          Comment


          • #6
            That is strange as the first service should be just another client to the second one.

            Could you post the application context of the first service, where you access the second one?
            And the stacktrace would also be helpful.

            Comment


            • #7
              HTML Code:
              <beans>
                <bean id="LookupService" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean"
                  <property name="jndiName">
                     <value>Lookup</value>
                  </property>
                  <property name="jndiEnvironment">
                    <props>
                      <prop key="java.naming.factory.initial">com.evermind.server.rmi.RMIInitialContextFactory</prop>
                      <prop key="java.naming.provider.url">ormi://localhost:23791/Lookup</prop>
                    </props>
                    <!-- Security credentials omitted -->
                  </property>
                  <property name="businessInterface">
                    <value>services.LookupService</value>
                  </property>
                  <property name="homeInterface">
                      <value>services.LookupHome</value>
                  </property>
                  <property name="refreshHomeOnConnectFailure">
                      <value>true</value>
                  </property>
                </bean>
              <beans>

              Stacktrace:

              org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'lookupImpl' defined in class path resource [beanRefContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/core/JdbcTemplate
              Caused by:java.lang.NoClassDefFoundError: org/springframework/jdbc/core/JdbcTemplate
              at java.lang.Class.getDeclaredMethods0(Native Method)

              Comment


              • #8
                The context seems ok so far. I guess you access LookupService in the initialization of your first service and store it in your EJB?.
                The stacktrace seems somehwat short. I guess the error happens when you invoke a method on the "LookupService" bean, so a complete trace including the invocation point might be useful.

                Comment


                • #9
                  Sorry for late reply. Lots of meetings.

                  I am unfortunately sitting on a closed net, so I can't just copy-paste the whole stacktrace out (and it is a 2 page trace).

                  But I see the service invoke the other service in an java.lang.reflect.Method.invoke()

                  Then AbstractStatelessSessionBean.ejbCreate is called, which calls loadBeanFactory, which after a few calls creates the application context:

                  ContextJndiBeanFactoryLocator.createApplicationCon text

                  What confuses me is the fact that the AbstractStatelessSessionBean and ContextJndiBeanFactoryLocator classes are found, but the JdbcTemplate is not found.

                  I am sorry I can't copy all the traces to you, and it is therefore hard for you to find out I was just hoping someone had some pointers.

                  Comment


                  • #10
                    Originally posted by richared View Post
                    But I see the service invoke the other service in an java.lang.reflect.Method.invoke()
                    But I take it that it is a normal remote invocation and the exception is wrapped inside a RemoteException.

                    Originally posted by richared View Post
                    Then AbstractStatelessSessionBean.ejbCreate is called, which calls loadBeanFactory, which after a few calls creates the application context:
                    Can you try accessing the service first from a "normal" client in order to have the session bean pool populated (assuming a minimum pool size > 0)? After that try from your second service.
                    Just to see whether invoking a method on an already instantiated bean also fails.

                    Originally posted by richared View Post
                    What confuses me is the fact that the AbstractStatelessSessionBean and ContextJndiBeanFactoryLocator classes are found, but the JdbcTemplate is not found.
                    Yes, that's strange. Do you use the all-in-one spring.jar?
                    Besides that: Could you try deploying the services on two different machines? Maybe the app server does some optimizations because it determines that a remote invocation is not necessary. In that case class-loader issues could surface.

                    Regards,
                    Andreas

                    Comment

                    Working...
                    X