Split Spring Application Context Files by Functionality for Easy Maintenance

Split Spring Application Context Files by Functionality for Easy Maintenance

I work with the Spring framework on a daily basis, and the one thing that always bothers me is when projects and people fail to adequately split and maintain their application context files. I’ve work with projects that put all of their Spring beans into the same file with no actual format or structure. That causes a significant nightmare when attempting to maintain, update, or add functionality on top of those files.

Therefore, I’m a firm believer that application context files should be split according to the functionality of their contents. When I create a new Spring project, I make sure that the following files are put into place before any development begins to ensure that any created beans are put into their proper place.

  • applicationContext-datasource.xml: This file contains all data source references used in the application.
  • applicationContext-dao.xml: This file contains all data access objects used for retrieving data from a data source.
  • applicationContext-service.xml: This file contains all service layer business logic.
  • applicationContext-controller.xml: I include this file if the application is a SpringMVC application. It includes handler mappings and controllers.
  • applicationContext-config.xml: This file contains basic configuration information. Things such as defined property files, and other required beans.
  • applicationContext-security.xml: I include this file if the project uses Spring Security as its security layer.
  • applicationContext-struts.xml: If you’re integrating Spring into your Struts application, I include this file to handle all Spring bean definitions for the actual Struts Action objects.

This list can easily be added upon, as you find specific needs for your application. As you split your Spring application context files you will find it will ease maintenance and development considerably.

Author: daharveyjr

I’m a solution architect responsible for the design, development, implementation, testing, and maintenance of e-commerce operations and applications using the Hybris and WebSphere Commerce product suites and other web technologies such as Java, J2EE/JEE, Spring, PHP, WordPress and more. Twitter | Facebook | LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *