Autowiring Your Bean

In all the examples so far, we have had to define explicitly, via the configuration file, how the individual beans are wired together. If you don’t like having to wire all your components together, you can have Spring attempt to do so automatically. By default, autowiring is disabled. To enable it, you specify which method of autowiring you want to use by using the autowire attribute of the bean you want to autowire.

Modes of Autowiring

Spring supports five modes for autowiring: byName, byType, constructor, default, and no (which is the default). When using byName autowiring, Spring attempts to wire each property to a bean of the same name. So, if the target bean has a property named foo and a foo bean is defined in the ...

Get Pro Spring,Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.