Announcement Announcement Module
Collapse
No announcement yet.
application context file size Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • application context file size

    Hi,

    I'm fairly new to Spring and i'm really enjoying it. I have one question about the application context file.

    I'm working on a web application that uses Spring and Hibernate. My problem is that the application context file is becoming a little too big to be easily readable.

    That's why I'd like to know if it's possible to split this file into several smaller ones and then setup Spring so that it can load them up ?

    If this solution is not possible, do you know an ant task that allows you to merge xml files ? Then I could work on smaller files and run an ant task that merges them all into a bigger application context file.

    I know it stricly isn't about Spring, but I think it's an issue that can be faced for really big webapp.

    Thanks in advance for your help.

    Vince

  • #2
    I'd like to know if it's possible to split this file into several smaller ones and then setup Spring so that it can load them up ?
    Yes it's possible. In a web-app you can do something like:
    Code:
    <context-param>
    	<param-name>contextConfigLocation</param-name>
    	<param-value>
    		/WEB-INF/applicationContext.xml /WEB-INF/schedulingContext-quartz.xml
    	</param-value>
    </context-param>
    In addition, the servlet context is loaded by:
    Code:
    <servlet>
    	<servlet-name>context</servlet-name>
    	<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    	<load-on-startup>1</load-on-startup>
    </servlet>
    The default id defined in "{servlet-name}-servlet.xml"

    In an application you can do something like:
    Code:
    String&#91;&#93; paths = new String&#91;&#93; &#123;"applicationContext.xml", "schedulingContext-quartz.xml"&#125;;
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext&#40;paths&#41;;

    Comment


    • #3
      You can also use <import/> tag in your "parent" context to auto-import your "children" contexts and have your context loading independent of your file splitting strategy.

      Comment


      • #4
        Thanks

        Both solutions work like a charm !

        Thank you very much for your help !

        Vince

        Comment

        Working...
        X