This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
First there are Annotation alternatives that will require very minimum in the xml.
For the xml, you do want to split them up into separate files so that you have a clear separation of concerns even in xml.
For instance the applicationContext.xml is only for you Service/Repository layers. You would probably want to import an infrastructure-config.xml for things like Datasources and TransactionManagers. Then if you are using AOP you might want to create and import an aspect-config.xml. This is so that it is easy to find anything you might want to change. Want to change a Pointcut, well go to aspect-config.xml. Want to change a Serviceconfig, well applicationContext.xml
As far as the SpringMVC stuff. The xxx-servlet.xml is where you define your Controllers, and View resolvers, and if for MappingHandlers (if you don't want to use the default). That is all.
So with annotations I can have two lines in my applicationContext.xml that points to the package that holds the Service and Repository implementation classes with Annotations. In the xxx-servlet.xml I can put the scan for the package that has the Controller classes, and one entry for a Resolver. Real small and simple
Also the difference between the applicationContext.xml and the xxx-servlet.xml is huge. a separation of concerns. The applicationContext can be re-used by many Servlets / web apps. So you can have your application layers available to a Spring MVC app and also to Spring web services without having to duplicate it all. Also when those two xml files really get loaded are at different times and placed in different locations when in a Web environment.
Thanks for the reply! Well, I couldn't really understand thr following point.Could you give me an example?
The applicationContext can be re-used by many Servlets / web apps. So you can have your application layers available to a Spring MVC app and also to Spring web services without having to duplicate it all.
Simple, all you would need to do is have two <servlet> tags one for the DispatcherServlet and one for the Web Service Servlet. But you still only have one ContextLoaderListener to load the application context.
Basic layered architecture of a Spring app with both a Web Layer and a Web Service, but only one Application Context. So you want both Web stuff to share the one Application Context rather than creating two of them.