java - why spring 4 recommend annotation rather than configuration file? -


recently i'm learning spring framework of java. curious why spring 4 recommend annotation set spring rather using configuration file? people said spring configuration file complicated. think using annotation going opposite direction of purpose of dependency injection because using annotation must change our source code when changed. why annotation more applicable configuration file ?

in opinion, benefits of annotations on xml in spring are:

  • less boilerplate, xml verbose.
  • ide integration easier , arguably more effective (autocomplete, javadoc, refactorisation...).
  • typos detected @ compilation time.
  • you not need @ 2 different places find configuration affects 1 class.
  • spring boot favours convention on configuration, of time need override few things, , not need xml config file that. following route because makes sense product , argue consistent across whole spring family.

on other hand, xml has own benefits like:

  • configuration centralised.
  • you can use same class 2 different configurations in xml.
  • you not need recompile when making change.

but apparently benefits not enough xml preferred method. in end, more matter of preference else.

hope helps.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -