Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>1), 4) There are two separate ways of autowiring in Spring: XML-based and annotaion-based. </p> <p>XML-based autowiring is activated from XML config, as described <a href="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-autowire" rel="nofollow">here</a>. In the end, it will call setter method, so <code>setStudent()</code> method is required here.</p> <p>Annonation-based autowiring, on the other hand, is performed via reflection magic. It attempts to fill everything you mark with <code>@Autowired</code> annotation. In fact, it can set private field with no accessors, as in</p> <pre><code>public class Foo { @Autowired private Thingy thing; // No getThing or setThing methods private void doStuff() { // thing is usable here } } </code></pre> <p>For <code>@Autowired</code> annotaion to work, you will need to define corresponding bean post-processor; it is done by adding the following line to xml config:</p> <pre><code>&lt;context:annotation-config/&gt; </code></pre> <p>Note, that these two autowiring methods are independant, and it is possible(but not recommended) to use them simultaneously. In that case, xml autowiring will override annotations.</p> <p>2) In general, autowiring will fail, if it cannot find one and only one candidate for injection. So, in your case, it will fail with exception upon container creation. There are some fallback quirks, but in general it works reliably.</p> <p>3) Yes, documentaion says so.</p> <p>About <code>byName</code> and <code>byType</code> autowiring. While <code>byName</code> autowiring simply tries to match bean name (can be specified with <code>id</code> attribute), <code>byType</code> is a bit more complex than <code>class</code> attribute lookup. It searches beans by <em>type</em>, and it will match interfaces. Example:</p> <pre><code>public interface SomeService { void doStuff(); } public class SomeServiceImpl implements SomeService { @Override public void doStuff() { // Implementation }; } public class ServiceUser { @Autowired private SomeService someService; // SomeServiceImpl instance goes here } </code></pre> <p>P.S. You are referencing two different versions of Spring in your question, 2.5 and 3.0. Autowiring behavior is same in both.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload