<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>http://rasimsen.com/index.php?action=history&amp;feed=atom&amp;title=Autowiring_Dependencies</id>
	<title>Autowiring Dependencies - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://rasimsen.com/index.php?action=history&amp;feed=atom&amp;title=Autowiring_Dependencies"/>
	<link rel="alternate" type="text/html" href="http://rasimsen.com/index.php?title=Autowiring_Dependencies&amp;action=history"/>
	<updated>2026-04-23T05:54:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>http://rasimsen.com/index.php?title=Autowiring_Dependencies&amp;diff=183&amp;oldid=prev</id>
		<title>Rasimsen: Created page with &quot;Wiring allows the Spring container to automatically resolve dependencies between collaborating beans by inspecting the beans that have been defined.  There are four modes of a...&quot;</title>
		<link rel="alternate" type="text/html" href="http://rasimsen.com/index.php?title=Autowiring_Dependencies&amp;diff=183&amp;oldid=prev"/>
		<updated>2018-06-03T11:54:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Wiring allows the Spring container to automatically resolve dependencies between collaborating beans by inspecting the beans that have been defined.  There are four modes of a...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Wiring allows the Spring container to automatically resolve dependencies between collaborating beans by inspecting the beans that have been defined.&lt;br /&gt;
&lt;br /&gt;
There are four modes of autowiring a bean using an XML configuration:&lt;br /&gt;
&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;no&amp;#039;&amp;#039;&amp;#039;: the default value – this means no autowiring is used for the bean and we have to explicitly name the dependencies&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;byName&amp;#039;&amp;#039;&amp;#039;: autowiring is done based on the name of the property, therefore Spring will look for a bean with the same name as the property that needs to be set&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;byType&amp;#039;&amp;#039;&amp;#039;: similar to the byName autowiring, only based on the type of the property. This means Spring will look for a bean with the same type of the property to set. If there’s more than one bean of that type, the framework throws an exception.&lt;br /&gt;
*&amp;#039;&amp;#039;&amp;#039;constructor&amp;#039;&amp;#039;&amp;#039;: autowiring is done based on constructor arguments, meaning Spring will look for beans with the same type as the constructor arguments&lt;br /&gt;
&lt;br /&gt;
For example, let’s autowire the item1 bean defined above by type into the store bean:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
@Bean(autowire = Autowire.BY_TYPE)&lt;br /&gt;
public class Store {&lt;br /&gt;
     &lt;br /&gt;
    private Item item;&lt;br /&gt;
 &lt;br /&gt;
    public setItem(Item item){&lt;br /&gt;
        this.item = item;    &lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can also inject beans using the @Autowired annotation for autowiring by type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
public class Store {&lt;br /&gt;
     &lt;br /&gt;
    @Autowired&lt;br /&gt;
    private Item item;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If there’s more than one bean of the same type, we can use the @Qualifier annotation to reference a bean by name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
public class Store {&lt;br /&gt;
     &lt;br /&gt;
    @Autowired&lt;br /&gt;
    @Qualifier(&amp;quot;item1&amp;quot;)&lt;br /&gt;
    private Item item;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, let’s autowire beans by type through XML configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
&amp;lt;bean id=&amp;quot;store&amp;quot; class=&amp;quot;org.baeldung.store.Store&amp;quot; autowire=&amp;quot;byType&amp;quot;&amp;gt; &amp;lt;/bean&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, let’s inject a bean named item into the item property of store bean by name through XML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;bean id=&amp;quot;item&amp;quot; class=&amp;quot;org.baeldung.store.ItemImpl1&amp;quot; /&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;bean id=&amp;quot;store&amp;quot; class=&amp;quot;org.baeldung.store.Store&amp;quot; autowire=&amp;quot;byName&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/bean&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We can also override the autowiring by defining dependencies explicitly through constructor arguments or setters.&lt;/div&gt;</summary>
		<author><name>Rasimsen</name></author>
		
	</entry>
</feed>