Results 1 to 5 of 5

Thread: How to use ContextSingletonBeanFactoryLocator

  1. #1
    Join Date
    Aug 2005
    Posts
    5

    Default 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. #2
    Join Date
    Aug 2005
    Posts
    3

    Default

    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

  3. #3
    Join Date
    Sep 2004
    Location
    Christchurch, New Zealand
    Posts
    73

    Default

    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

  4. #4
    Join Date
    Aug 2005
    Posts
    3

    Default

    Thanks Chris! Works fine.

    Regards,
    Bert

  5. #5

    Default ContextSingletonBeanFactoryLocator

    Here is a post about this.
    "The highest form of grace is silence"

Posting Permissions

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