Results 1 to 6 of 6

Thread: Multiple context files in a non-web app?

  1. #1
    Join Date
    Mar 2005
    Posts
    25

    Default Multiple context files in a non-web app?

    I know how to set up a web based application to use multiple application context files:

    Code:
    <!-- In my web.xml file-->
    <context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/applicationContext-1.xml
    			/WEB-INF/applicationContext-2.xml
    			/WEB-INF/applicationContext-3.xml
    		</param-value>
    	</context-param>
    How do you do this in a non-web based app (no web.xml file) using a BeanFactory?

    Everything seems to be based on a web-app!

    Thanks.

  2. #2
    Join Date
    Mar 2005
    Posts
    25

    Default

    Hold on....think I found it.

    Code:
    String[] configFiles = new String[] { "applicationcontext1.xml",
                                          "applicationcontext2.xml" };
    BeanFactory factory = new ClassPathXmlApplicationContext(configFiles);

  3. #3
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    Not the most elegant solution, but this can serve as a placeholder until you get a better answer:

    Code:
    public static void main() {
    
    BeanFactory bean1 = new XmlBeanFactory(new FileSystemResource("config1.xml");
    
    BeanFactory bean2 = new XmlBeanFactory(new FileSystemResource("config2.xml");
    
    Object abc = bean1.getBean(....);
    Object bcd = bean2.getBean(....);
    
    }
    There is also an XmlBeanFactory two-arg constructor that has capabilities for inheritance. Pro Spring (p. 72) describes it, description probably also available somewhere in the online docs/API.

    Glen

  4. #4
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    Also, another person gave the below link for a similar question--you can use "import" within your config files as well:

    http://static.springframework.org/sp...ory-xml-import

    Glen

  5. #5
    Join Date
    Mar 2005
    Posts
    25

  6. #6
    Join Date
    Feb 2006
    Location
    Arlington, VA, USA
    Posts
    194

    Default

    Yes, it is nice that Spring allows you to accumulate multiple XML config files together under a single BeanFactory instance.

    Glen

Posting Permissions

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