Skip to content

Instantly share code, notes, and snippets.

@rponte rponte/gist:1332286
Created Nov 1, 2011

Embed
What would you like to do?
Spring Advice: autowiring interface types rather than class types
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
You can’t perform that action at this time.