views:

1910

answers:

2

Hello,

I would like to have step-by-step information on :

how to split the ApplicationContext file (eg.: myapp-servlet.xml) into multiple XML files in Spring with some examples ?

I have tried configuring web.xml with "ContextLoaderListener" and have contextConfigLocation like :

<init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value> /WEB-INF/business-services.xml </param-value>
    </init-param>

but it is creating problems.

Please give me in-detail explaination on how to do this.

Thanks in advance !

+2  A: 

e.g. with:

    <param-value>classpath*:spring/persistence/*.xml, classpath*:spring/*.xml</param-value>

the paths depend on your locations of the splitted .xml

Example with WEB-INF Directories

<param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>

sidenote: seems to work without ','

Reference:

  • spring doc chapter: 3.8.5. Convenient ApplicationContext instantiation for web applications
Michael Lange
Hi Michael, Thanks for your response !But what if I have added the splitted .xml files at /WEB-INF/ folder itself?Should I put CLASSPATH in this case also or simple <param-value> /WEB-INF/business-services.xml </param-value> entry should work?Please guide me on this.
see edited answer, should work with wildcards too
Michael Lange
+2  A: 

What I like to do, if I have multiple context files, is to have my base context class import the other pieces via the import tag.

<import resource="applicationContext-otherStuff.xml"/>

We typically use this model, to keep out datasource configuration separate from the bean instantiations.

Nick