Results 1 to 6 of 6

Thread: Spring - sharing file resource context

  1. #1
    Join Date
    Oct 2004
    Location
    Switzerland
    Posts
    45

    Default Spring - sharing file resource context

    Hi all,

    I want to share the application context between several plain Java clients to reduce the startup time of the Spring container.

    Currently I'm using a XmlBeanDefinitionReader to load my beans:

    Code:
        GenericApplicationContext appCtx = new GenericApplicationContext();
        XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(
                        appCtx);
        xmlReader.loadBeanDefinitions(new FileSystemResource(configfile));
        appCtx.refresh();
    
        Service service = (Service) appCtx
                        .getBean("service");

    I've done this because of being able to split up my application context into several files and load the configuration via FileSystemResource.

    Is it possible to share the context between several clients using the SingletonBeanFactoryLocator and still using the FileReader?


    My app-context looks like this:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	
    	<!-- import different backend configuration file -->
    	<import resource="applicationContext-1.xml"/>
    	<import resource="applicationContext-2.xml"/>
    	<import resource="applicationContext-3.xml"/>
    
    ....

    Cheers,
    Pieper

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Is it possible to share the context between several clients using the SingletonBeanFactoryLocator and still using the FileReader?
    What do you mean? If you are using the SingletonBeanFactoryLocator you should use it to get a hold of the context since the XmlBeanDefinitionReader will instantiate a new context.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Oct 2004
    Location
    Switzerland
    Posts
    45

    Default

    Hi all,

    sorry for being unprecise.

    I'm currently using XmlBeanDefinitionReader and I want to exchange that with something like the SingletonBeanFactoryLocator.

    But I want to specify the main applicationContext.xml not within the beanReference.xml, but within the code, because my java client is getting the configuration file name (absolute path) from an other software.

    My target is to hold the context in a singleton, but specify the main application context file as a file resource with an absolute path.

    Cheers,
    Pieper

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    In this case you should extend/customize the SingletonBeanFactoryLocator or create your own implementation which provides a dynamic configuration. FactoryLocators need to use a well known location when initializing so they can load the context for other clients - if you don't want to use beanReference.xml then you have to take the matter into your own hands.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Oct 2004
    Location
    Switzerland
    Posts
    45

    Default

    Quote Originally Posted by costin
    FactoryLocators need to use a well known location when initializing so they can load the context for other clients.
    I want to have a well known location, but specifiy that within the code and not within a beanFactory file.

    My issue is, that I have an absolute path for my config file, which resides somewhere in the filesystem. I don't want to have five entries in my beanReference file, which starts with an absolute path like C:/spring/config etc.pp.

    Cheers,
    Pieper

  6. #6
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    The beanRefFactory.xml used by SingletonBeanFactoryLocator is just an application context file itself. The factoryKey is the name of an object which is a BeanFactory of some sort. So if you can define what you want in beanRefFactory.xml, you should be all set.

    You might have to create a subclass that implements the functionality you are talking about in the constructor.
    Bill

Posting Permissions

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