title: Spring Bean with Abstract classes
body: <p>I wanted to know how Spring DI works with Abstract classes.
  For example take look at below two samples:</p>
  
  <p>Dao layer:</p>
  
  <pre><code>  public abstract class BaseDaoImpl&lt;T extends ShoppingCartEntity&gt; implements BaseDao&lt;T&gt; {
      @Autowired
      protected SessionFactory sessionFactory;
  
      private Class&lt;T&gt; entityClass;
  
      public BaseDaoImpl(Class&lt;T&gt; entityClass) {
        super();
        this.entityClass = entityClass;
      }
  
     //common dao layer methods like getAll(),save(entity) etc
    }
  </code></pre>
  
  <p>I haven't marked BaseDaoImpl with <code>@Repository("baseDao")</code> annotation but still it was able inject the <code>@Autowired</code> dependency on sessionFactory instance.</p>
  
  <p>Service layer:</p>
  
  <pre><code>@Service("baseService")
  public abstract class BaseServiceImpl implements Serializable {
  
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
  
    @Autowired
    private DaoProvider daoProvider;
    //other fields
    }
  </code></pre>
  
  <p>Here I have marked the BaseService as abstract and also <code>@Service</code> annotation is used which will register the BaseService  class as Spring Bean component for service layer.</p>
  
  <p>Now,I have two questions:</p>
  
  <ol>
  <li><p><strong>If a class is abstract then How does Spring create a bean from it?</strong></p></li>
  <li><p><strong>If a class is not marked with any spring bean component
  annotation(like <code>@Component,@Repository,@Service or @Conroller</code>)
  should we be able to Autowired dependencies on these
  classes?</strong>(like my daoLayer base class which is not a spring bean
  component but still I'm able to inject </p>
  
  <p><code>@Autowired
   protected SessionFactory sessionFactory;</code></p></li>
  </ol>