title: Is it mandatory in Spring specify an id for each declared bean?
body: <p>I am studying for the Spring Core certification and I have some doubt to the following question finded on this old exam mock (this is related to the Spring v3 and now there is the v4 but I think that many topics are the same).</p>
  
  <p>Given the following Spring configuration file, what is the correct answer:</p>
  
  <pre><code>&lt;bean class ="com.spring.service.MyServiceImpl"&gt;
      &lt;property name="repository" ref="jpaDao" /&gt;
  &lt;/bean&gt;
  
  &lt;bean class="com.spring.repository.JpaDao"/&gt;
  </code></pre>
  
  <ol>
  <li><p>The first declared bean MyServiceImpl is missing an id must be named myService.</p></li>
  <li><p>The second declared bean JpaDao is missing an id must be named jpaDao</p></li>
  <li><p>Answers 1 and 2 are both rights</p></li>
  <li><p>Answers 1 and 2 are both wrong</p></li>
  </ol>
  
  <p>My original idea is that both the answer are right because both the bean have no id specified so if it is true that the second bean need an <strong>id=jpaDao</strong> because the first one use it as reference I thought that also the first been need an id. Otherwise how can it be called? (also in the code from the factory?)</p>
  
  <p>But reading the anser finded into the mock it say that the right answer is the second.</p>
  
  <p>So what it means? that in Spring is not mandatary specify an id for each bean? If it is true how can I referer or instantiate the first bean using the factory if it have no id? What am I missing?</p>
  
  <p>Tnx</p>