title: Spring autowiring issues on paramaterized class
body: <p>I have been struggling with this issue for a while and have browsed a lot of articles, but couldnt figure out the solution. Appreciate your help with the issue below.</p>
  
  <p>I need to be able to autowire the EntityManager in the service class, but throws an exception. The default constructor probably has issues because of type erasure and so I tried using a constructor with parameters to set the Type. How do I autowire EntityManager of type User? </p>
  
  <pre><code>public interface IEntityManager&lt;T extends IDomain&lt;ID&gt;, ID extends Serializable&gt; {
  
      T findById(ID id, boolean lock);
  
      T save(T entity);
  
      void delete(T entity);
  }
  
  public class EntityManager&lt;T extends IDomain&lt;ID&gt;, ID extends Serializable&gt; 
          implements IEntityManager&lt;T, ID&gt; {
  
      private Class&lt;T&gt; entity;
  
      @Autowired(required=true)
      private SessionFactory sessionFactory;
  
      /*
      @SuppressWarnings("unchecked")
      public EntityManager() {
          this.entity = (Class&lt;T&gt;) ((ParameterizedType) getClass()
                              .getGenericSuperclass()).getActualTypeArguments()[0];
  
      } */
  
      @Autowired(required=true)
      public EntityManager(Class&lt;T&gt; entity) {
          this.entity = entity;
      }
  }
  
  @Service("UserService")
  @Transactional
  public class UserServiceImpl implements IUserService {
  
      @Autowired  
      EntityManager&lt;User, Integer&gt; entityManager;
  }
  </code></pre>
  
  <p>Here is the exception:</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UserService': Injection of autowired dependencies failed; 
  nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.test.dummy.persistence.manager.EntityManager com.test.dummy.service.UserServiceImpl.entityManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.test.dummy.persistence.manager.EntityManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
  </code></pre>