Rule Definition
Auto-wiring can save you time in small applications, but in many cases, it leads to bad practices and is inflexible in large applications. Using byName seems like a good idea, but it may lead you to give your classes artificial property names so that you can take advantage of the auto-wiring functionality. The whole idea behind Spring is that you can create your classes how you like and have Spring work for you, not the other way around. You may be tempted to use byType until you realize
that you can only have one bean for each type in your BeanFactory -- a restriction that is problematic when you need to maintain beans with different configurations of the same type.
Also it will affect the performance of your application since auto-wiring is slow.
Remediation
Define your wiring explicitly, and you benefit from explicit semantics and full flexibility on property naming and on how many instances of
the same type you manage.
Violation Code Sample
<beans>
<bean id="myBean" autowire="byName" class="com.cast.MyBean"/> // VIOLATION
...
</beans>
Fixed Code Sample
<beans>
<bean id="myBean" class="com.cast.MyBean"/> // FIXED
...
</beans>
Reference
http://www.onjava.com/pub/a/onjava/2006/01/25/spring-xml-configuration-best-practices.html
http://code.google.com/p/google-guice/wiki/SpringComparison
Related Technologies
JEE
Technical Criterion
CWE-609 - Double-Checked Locking
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.