Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring Dependency Injection - xml vs annotations - common practice  RSS feed

 
y roni
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Are you using Spring Dependency Injection with XML configurations or Java annotations (or both)?
I have read the pros & cons, just want to know want is the common practice.
Thanks!
 
Stephan van Hulst
Saloon Keeper
Posts: 7706
141
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This goes not just for dependency injection, but for anything where there's an option to use both XML configuration and annotations: Prefer annotations for settings that are unlikely to change, and XML for settings that can change after deployment.
 
Peter Rooke
Ranch Hand
Posts: 859
1
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, java configuration is the way to go*.  Main reasons for this are that this means the configuration is in one central place (same as XML), but also it provides type safety.

However as soon as you start using anything like spring boot, you will also start to use component scanning to configure resources, as well as using java config for the dependency injection in your code.   

* with two exceptions (IMHO) - XML is far easier to understand when using security and integration.  And STS can display a graphical representation of the integration components when used with XML. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!