Announcement Announcement Module
Collapse
No announcement yet.
How to use ContextSingletonBeanFactoryLocator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use ContextSingletonBeanFactoryLocator

    Hi,

    Sorry if this has been covered over and over, but I can't find a definitive example that works.

    I want to have a single spring context in my application, loaded once at startup, that mulitple ejbs can get hold of.

    I know I should be using SingletonBeanFactoryLocator or ContextSingletonBeanFactoryLocator and initialising it in setSessionContext. Then I can get my beans using getBeanFactory().getBean() in onEjbCreate right?

    Any chance of an idiots guide to getting this working.

    Many thanks,

    Richard.

  • #2
    Same goes for me I'm afraid.... I've created some webservices that use mutiple EJBs (WSAD). In stead of each EJB initializing the ApplicationContext, I'd like to let it be initialized only once.

    Hopefully someone out there can help us on our way?

    Regards,
    Bert

    Comment


    • #3
      In the bean:

      Code:
          public void setSessionContext(SessionContext sessionContext) {
      
              super.setSessionContext(sessionContext);
      
              setBeanFactoryLocatorKey("global.spring.ejb.context");
              setBeanFactoryLocator(SingletonBeanFactoryLocator.getInstance());
          }
      In beanRefFactory.xml at the top level in your ejb jar:

      Code:
      <?xml version='1.0' encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
      
      <beans>
       
        <bean id="global.spring.ejb.context"
            class="org.springframework.context.support.ClassPathXmlApplicationContext">
          <constructor-arg>
            <list>
              <value>META-INF/dataAccessContext-jta.xml</value>
              <value>META-INF/businessContext.xml</value>
            </list>
          </constructor-arg>
        </bean>
          
      </beans>
      Then put your business login POJO spring context in META-INF/businessContext.xml and dao spring context in META-INF/dataAccessContext-jta.xml.

      good luck,
      Chris

      Comment


      • #4
        Thanks Chris! Works fine.

        Regards,
        Bert

        Comment


        • #5
          ContextSingletonBeanFactoryLocator

          Here is a post about this.

          Comment

          Working...
          X