Announcement Announcement Module
Collapse
No announcement yet.
Multiple context files in a non-web app? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Hold on....think I found it.

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

    Comment


    • #3
      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

      Comment


      • #4
        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

        Comment


        • #5
          I also found this: http://www.devx.com/Java/Article/21665/0/page/3

          Comment


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

            Glen

            Comment

            Working...
            X