Results 1 to 10 of 10

Thread: Accessing EJB from within another EJB

  1. #1
    Join Date
    Jan 2007
    Location
    Norway.
    Posts
    20

    Default 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 at 01:34 AM.
    Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. (Henry Spencer)

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    You could use SimpleRemoteStatelessSessionProxyFactoryBean to refer to the external service.

    Regards,
    Andreas

  3. #3
    Join Date
    Jan 2007
    Location
    Norway.
    Posts
    20

    Default

    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.
    Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. (Henry Spencer)

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

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

  5. #5
    Join Date
    Jan 2007
    Location
    Norway.
    Posts
    20

    Default

    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.
    Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. (Henry Spencer)

  6. #6
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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.

  7. #7
    Join Date
    Jan 2007
    Location
    Norway.
    Posts
    20

    Default

    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)
    Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. (Henry Spencer)

  8. #8
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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.

  9. #9
    Join Date
    Jan 2007
    Location
    Norway.
    Posts
    20

    Default

    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.
    Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. (Henry Spencer)

  10. #10
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote 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.

    Quote 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.

    Quote 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

Posting Permissions

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