wood burning stoves 2.0
The moose likes Spring and the fly likes Spring context xml files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring context xml files" Watch "Spring context xml files" New topic

Spring context xml files

andy kumar
Ranch Hand

Joined: Jun 08, 2009
Posts: 64
In a big enterprise application built using Spring how should the spring-context.xml file be split into more than one file so that we can avoid having a single file which is very huge. Are there any patterns or guidelines that should be followed while making the xml file so that it does not become very big.

In case I plan to split my xml file based on the business logic or the manner in which I have coded my application, is it possible to load them at the same time as there may be some DI class from one xml file to another.
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 471

It all depends on your design, and how you split your application (for example, are you packaging per layer or per feature). However, here's what I think. You should have an XML file per module, and if that is still huge, you can still split that into separate XML files depending on the layer, for example
  • module-x-context.xml
  • module-y-dao-context.xml
  • module-y-service-context.xml
  • module-z-context.xml

  • As for your question regarding if you can inject beans defined in one XML into another bean defined in another XML, this is a sure thing (if you are loading all of the XML files in the same application context of course). Finally, if you are using eclipse, you can use the spring-ide plugin to define the different files, and you can create different sets of beans, which is going to help you with auto completion, and tells you if a bean you are referring to does not exist.

    Visit my blog: http://jnassef.blogspot.com/
    XiaoM Kevin

    Joined: Dec 29, 2009
    Posts: 2
    Alaa is right.You can split the xml file based on any module,and split the module xml file based on your application`s layer.
    I agree. Here's the link: http://aspose.com/file-tools
    subject: Spring context xml files
    It's not a secret anymore!