title: Spring. Dynamic dependency injection
body: <p>I have the following problem.</p>
  
  <p>I have a generic class A</p>
  
  <pre><code>public class A&lt;T, DAO extends JpaRepository&lt;?, ?&gt;&gt;
  {    
  
      @Autowired
      protected DAO daoObject;
  
      ......
  </code></pre>
  
  <p>and there I am trying inject a genreic DAO-object of the JpaRepository-type.</p>
  
  <p>If I have only one implemetation of injected object(of JpaRepository), then there is no problem, but if I have more then one, then spring doesn't know which object it is to inject and throws an exception.</p>
  
  <p>The question is: How can I dynamish based on generic information, inject the correct object?</p>
  
  <p>Thank you.</p>
  
  <pre><code>public interface IRegisteredUserDAO extends JpaRepository&lt;RegisteredUser, String&gt; {
  
  }
  
  
  public interface IMailLogDao extends JpaRepository&lt;MailLog, Long&gt; {
  
     findByTo(String to);
  }
  </code></pre>
  
  <p>and i used it so</p>
  
  <pre><code>public class RegisteredUserVM extends YBTableViewModel&lt;RegisteredUser, IRegisteredUserDAO&gt;
  {
  </code></pre>
  
  <p>UPDATE:</p>
  
  <pre><code>public class MailLogVM extends YBTableViewModel&lt;MailLog, IMailLogDao&gt;
  {    
  
  }
  </code></pre>