title: How to autowire a generic bean in spring
body: <p>How to autowire a generic bean in spring?</p>
  
  <p>I have a dao implement as follows:</p>
  
  <pre><code>@Transactional
  public class GenericDaoImpl&lt;T&gt; implements IGenericDao&lt;T&gt;
  {
  
      private Class&lt;T&gt; entityClass;
  
      @Autowired
      private SessionFactory sessionFactory;
  
      public GenericDaoImpl(Class&lt;T&gt; clazz) {
  
          this.entityClass = clazz;
      }
      ...
  }
  </code></pre>
  
  <p>Now I want to autowired the DaoImpl like this:</p>
  
  <pre><code>@Autowired
  GenericDaoImpl&lt;XXXEntity&gt; xxxEntityDao;
  </code></pre>
  
  <p>I config in the spring xml:</p>
  
  <pre><code>&lt;bean id="xxxEntityDao" class="XXX.GenericDaoImpl"&gt;
      &lt;constructor-arg name="clazz"&gt;
          &lt;value&gt;xxx.dao.model.xxxEntity&lt;/value&gt;
      &lt;/constructor-arg&gt;
      &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>But I doesn't work, How should I config it? or a good practice about generic Dao implement?</p>