title: Spring, @Autowired, @Resource and <property>
body: <p>This week I've been trying to learn Spring, JBoss, Maven, JPA and Hibernate and I've had a lot of fun with it. I am somewhat confused over the many different ways to inject resources in a class though. Until this week I was not even aware that you could inject resources in any other way than using the <code>&lt;property&gt;</code> tag in your Spring XML configuration.</p>
  
  <pre><code>&lt;bean id="catalogService" class="com.idbs.omics.catalog.service.CatalogService"&gt;
      &lt;property name="termDao" ref="termDao"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>When I started experimenting with JPA I encountered <code>@PersistenceContext</code>, but that seems to be a special case so fair enough. Then I started reading up on Spring's testing framework and I saw the first example that used <code>@Resource(name="catalogService")</code> and then in a Web Service example <code>@Autowired</code> crashed the party!</p>
  
  <pre><code>**The Question!**
  </code></pre>
  
  <p>So what is the difference between all these and is there right and wrong situation to use them in? I guess I'm looking for a best practice here.</p>
  
  <p>Cheers all</p>