Created
November 1, 2011 23:39
-
-
Save rponte/1332286 to your computer and use it in GitHub Desktop.
Spring Advice: autowiring interface types rather than class types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There's another good reason to autowire interface types rather than class types, which is that if Spring needs | |
to generate a proxy object around the bean before injecting it, then if the bean's class defines any | |
interfaces, then the proxy will implement those interfaces, and will not be type-compatible with the bean class | |
itself. If you then try and autowire that bean by class type, it will fail. The easiest way to avoid this | |
annoying scenario is to always autowire by interface type, that way it will lways work as you expect. | |
http://stackoverflow.com/questions/5288153/using-spring-to-wire-directly-a-concrete-class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment