ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Twelve Best Practices For Spring XML Configurations
Subject:   autowiring & constructor injection
Date:   2007-03-22 10:43:32
From:   HamletDRC
This was great... just a couple questions/comments:


1. Avoid using autowiring
The author feels autowiring "sacrifices the explicitness and maintainability of the configurations." For explicitness, if you follow Effective Java #26 (use overloading judiciously) then it doesn't seem to be much of a problem. 90+% of our classes have only 1 constructor. For maintainability, I contend that having to write constructors in XML takes a lot of extra time and isn't found in automated refactorings. To me, autowiring is more maintainable. I'd be interested in a further explanation of this one.


11. Prefer setter injection over constructor injection
The author states "setter injection is more flexible and manageable, especially when the class has multiple properties and some of them are optional." If the class does not have optional properties, then I'm not sure how setter injection is more flexible and manageable. Especially when it means sacrificing immutablility. I tend to side with Effective Java #13 (favor immutablity). Again, I'd be interested in a further discussion of this one.