Split application context file in Spring

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

How to split ApplicationContext file (ex: myapp-servlet.xml) into several XML files in Spring with some examples?

I tried setting up web.xml using "ContextLoaderListener" and had contextConfigLocation like:

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

but it creates problems.

Please give me a detailed explanation on how to do this.

Thanks in advance!

+4
source share
2 answers

What I like to do, if I have several context files, I need my base context class to import other parts using the import tag.

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

We typically use this model to keep the data source configuration separate from the bean instances.

+12
source

eg. with:

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

paths depend on your locations shared by .xml

Example with WEB-INF Directories

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

sidenote: seems to work without ','

Link:

  • spring doc chapter: 3.8.5. Convenient ApplicationContext instance for web applications
+3
source

All Articles