Announcement Announcement Module
Collapse
No announcement yet.
Using Bean Factory on 2nd attempt causes errors Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    The onEjbCreate() method should be called when the EJB is put into the "ready pool". This occurs before a bean instance can be returned from a jndi lookup. Are you saying the the onEjbCreate() method is never being called?

    I noticed that you don't have the @Stateless on the class.

    Code:
    @Stateless
    public class ExpensesEJBBean extends AbstractStatelessSessionBean implements ExpensesEJBLocal, ExpensesEJB {
    }
    
    If the onEjbCreate() method is not being called then there is no way the Spring initialization is done. Code from the AbstractStatelessSessionBean

    Code:
    public void ejbCreate() throws CreateException {
       loadBeanFactory();
       onEjbCreate();
    }
    This would lead me to believe that the session bean is not setup correctly in JBoss as the EJB lifecycle methods (ejbCreate(), etc) are not being called.

    Comment


    • #17
      Originally posted by cwash5 View Post
      The onEjbCreate() method should be called when the EJB is put into the "ready pool". This occurs before a bean instance can be returned from a jndi lookup. Are you saying the the onEjbCreate() method is never being called?

      I noticed that you don't have the @Stateless on the class.

      I have used
      Code:
      @Stateless(name = "ExpensesEJBBean", mappedName = "ExpensesEJBBean")


      Code:
      @Stateless
      public class ExpensesEJBBean extends AbstractStatelessSessionBean implements ExpensesEJBLocal, ExpensesEJB {
      }
      
      If the onEjbCreate() method is not being called then there is no way the Spring initialization is done. Code from the AbstractStatelessSessionBean

      Code:
      public void ejbCreate() throws CreateException {
         loadBeanFactory();
         onEjbCreate();
      }
      This would lead me to believe that the session bean is not setup correctly in JBoss as the EJB lifecycle methods (ejbCreate(), etc) are not being called.
      According to the JBoss server logs it does state that the "xxx EJB has been deployed". From which i can use InitialContext to get at it.

      Unfortunately most of experience was in EJB2 (though not touched it in over a year). From what i remeber of an EJB lifecylce was that because a stateless bean is being used the container would normally pre create a series of beans and then initalise it when called by the application.

      The constructor of my bean is being called by the spring framework, as i never directly initialize it myself, it happens via DI.

      I have a strong feeling that when Spring DI the EJB into the service object it actually injects it as a standard bean and not an EJB (explains why the container methods are not being called)

      Code:
      ctx.getBean("expensesService") //returns an ServiceObject containing DI EJB
      The service object returned from the call above I invoke the EJB, on invoking the EJB the call to onEJBCreate should be made(after ejbCreate)

      [CODE]
      <bean id="expensesService" class="uk.co.aztekSolutions.expensesApp.services.c ore.expenses.ExpensesServiceImpl">
      <property name="expensesEJB" ref="expensesEJB"/>
      </bean>

      <bean id="expensesEJB" class="org.springframework.jndi.JndiObjectFactoryB ean">
      <property name="jndiEnvironment">
      <props>
      <prop key="java.naming.factory.initial">org.jnp.interfac es.NamingContextFactory</prop>
      <prop key="java.naming.factory.url.pkgs">org.jboss.namin g:org.jnp.interfaces</prop>
      <prop key="java.naming.provider.url">jnp://localhost:1099</prop>
      </props>
      </property>
      <property name="jndiName" value="AztekApplication/ExpensesEJBBean/local"/>
      </bean>
      [/I]

      Comment


      • #18
        Solution Found

        In case anyone is interested I have finally managed to get my App (Struts+spring+EJB3+iBatis/Hibernate) to work. Having so many problems initially I took some drastic steps to get everything to work
        1. Completely removed Spring from the App and got it working without it.
        2. Added the spring libs to the root of the ear file only, allowing both EJB and Web app to access them
        3. Added a context listener to the web.xml and added an EJB bean to the applicationContext.xml and accessed it via the configured service beans also injected by Spring
        4. Web app is now able to access EJB3 using Spring.
        5. Finally in the EJB jar file added another applicationContext.xml and defined the domain layer beans to it, using the ClassPathXmlApplicationContext to access the resources.

        I believe my overall problem was I had two separate spring libs inside web war and ear root.

        This approach also meant there are no direct dependencies on Spring, so if tomorrow I decide to drop Spring the application will still work as if nothing has changed.

        (Whole point of this app was to decouple the domain/persistence layer from the web app and use the EJB layer, though in my instance there was any real benefit of the EJB layer but I would be in the position where I could completely drop the EJB layer and use Spring alone. This way I have more options available to me.)

        Comment

        Working...
        X