title: Get spring bean via context using generic
body: <p>I have a bunch of repository beans that implement type <code>Repository&lt;T ? extends Node&gt;</code>. Now I can get a list of random nodes from the user and I want to get the appropriate repository for each node. Since <a href="https://spring.io/blog/2013/11/01/spring-framework-4-0-rc1-available" rel="noreferrer">Spring 4.0RC1</a> we can autowire repositories like this:</p>
  
  <pre><code>@Autowired Repository&lt;SomeNode&gt; someNodeRepository;
  </code></pre>
  
  <p>As documented <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-generics-as-qualifiers" rel="noreferrer">here</a>.</p>
  
  <p>This works fine, but my question is how I can do this dynamically based on the generic type. </p>
  
  <p>What I want to do is something like:</p>
  
  <pre><code>public &lt;T extends Node&gt; T saveNode(T node) {
      Repository&lt;T&gt; repository = ctx.getBean(Repository.class, node.getClass());
      return repository.save(node);
  }
  </code></pre>
  
  <p>Where the second parameter is the generic type. <em>This of course does not work, although it compiles.</em></p>
  
  <p>I can't find any/the documentation on this. </p>