• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Spring Dependency Injection - xml vs annotations - common practice

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Saloon Keeper
Posts: 14665
330
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1108
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.  
 
reply
    Bookmark Topic Watch Topic
  • New Topic