Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming convention for Spring application context XML

Tags:

java

spring

I am deciding on a naming convention for my Spring application context files. I've come across this blog and a couple of tutorials suggesting applicationContext-<name>.xml is the way to go. I'm generally not a find of mixing camel case with dashes/underscores. What are some other naming conventions have you seen?

Edit: I'm also thinking of nesting context files inside the package that pertains to them. For example, my classes/interfaces that relates to ordering would go in context file com/mycompany/order/spring-context.xml. I would have a top-level applicationContext.xml that pulls everything together. Suggestions?

like image 268
0sumgain Avatar asked Aug 26 '09 12:08

0sumgain


2 Answers

I very much support the applicationContext-<name>.xml convention.

In general <name> refers to the Maven module name in all our projects. So, each module that requires a Spring configuration has its own applicationContext-<name>.xml file. The "execution module" i.e. the one module that represents the sort of the entry point into the application (WAR, EAR, etc.) has a single applicationContext.xml that only imports all the applicationContext-<name>.xml files.

We use this convention company-wide strictly in all our Maven/Spring projects and it's proved to be extremely simple, clear and efficient.

like image 101
Marcel Stör Avatar answered Sep 28 '22 06:09

Marcel Stör


If there were a convention, I would like it to be:

  1. files stored in packages (not in default package) to obviate potential naming conflicts and also means I don't have to include the app name in them, it's defined by the package.
  2. files named all lower case with a '-' to separate the names

I tend to prefix my spring config files with "spring" makes it more obvious what they are used for, but this is not necessarily mandatory.

But let me say this would work for the way that I've dealt with my spring files, may not work for all contexts.

IMHO applicationContext-<name>.xml is a little verbose (long) and I like all lowercase as it's differentiates them from my java source and (I think) makes them easier to read.

like image 41
Michael Wiles Avatar answered Sep 28 '22 07:09

Michael Wiles