Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

After having read through some of the Spring docs my inclination is towards using a XML config file rather than annotations on the classes themselves. My reasoning is that by doing so you avoid tying your POJOs to a particular framework.

Based on your experience with Spring, are there any advantages that XML configuration have over an annotation based configuration, and if not what are the disadvantages?

share|improve this question
Duplicate on SO:… – ftr May 23 '12 at 14:09
I edited your question to focus the question on the advantages or disadvantages of one approach over the other. Asking about reasons behind the popularity of a framework doesn't lead to a constructive question. – maple_shaft May 23 '12 at 16:29
duplicate of: Why were annotations introduced in Spring and Hibernate? – gnat Apr 10 '13 at 10:24

Many of the Spring annotations are now standardized (e.g. CDI for dependency injection), so you're not at all tying yourself to Spring by using them. And for those that aren't: your application won't work without the functionality, will it? So it's basically tied to Spring, whether or not you try to hide that fact.

Annotations are much better for maintainability because they're placed with the code they apply to, so you see them when reading the code. And they require less duplication of logic because what class they apply to is implicit in their placement, whereas XML config files always need to list the class name.

Most people prefer annotations nowadays for these reasons.

share|improve this answer
And for those that aren't: your application won't work without the functionality, will it? So it's basically tied to Spring, whether or not you try to hide that fact. Careful, dangerous amounts of common sense like that will not get you on the good side with the Ivory Tower Architects. – maple_shaft May 23 '12 at 16:25
@maple_shaft careful yourself, without all that ivory tower architecture it's just moving information from A to B. You're going to hurt some egos. – dsch Jun 29 '12 at 20:37

First, look at your organization. Depending on the experience and capacity to learn new things, Spring XML abstracts logic and functionality by removing the visual dependency chain from your Java files. If your development team is not accustomed to this type of development model, it can be a steep learning curve. Don't underestimate this point. I made this mistake with a group of very sharp developers and was surprised by the amount of overhead it added to the team.

I have found that using Spring Annotations, or any Java Annotations for that matter, offered significant development overhead reductions. This was due to the direct visual link they provided and seamless integration with your favorite IDEs. Having the ability to use current day-to-day tools in your development cycle like drilling down into source code, setting debugging break points, Javadoc tool-tips, etc, is not something to take for granted.

Now I know you can get a Spring Tool set for Eclipse, not sure of the others, but you are again adding a another layer of learning on your team.

share|improve this answer

I like using annotations for things that

  • are essential (like @Service)
  • won't change without a redeployment (like database column names)

I like using annotations for

  • global config (aspects)
  • things that could be changed by users of a component (security, role names, datasource jndi references), etc.

There is a thread at coderanch I really like on this topic. Craig Walls - the author of "Spring in Action" explains why he evolved from never using annotations to his current state.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.