title: Autowiring Concrete Class into Abstract Decorator
body: <p>Greetings ladies and gents,</p>
  
  <p>I'm implementing a system where we are trying to keep things highly flexible. We have an abstract superclass called <code>EmailTaskService</code> which has two classes inheriting from it. One is <code>EmailTaskServiceImpl</code> (the concrete implementation class), and the other is another abstract class called <code>ScheduledEmailTaskService</code> which has a subclass called <code>ScheduledEmailTaskServiceImpl</code>.</p>
  
  <p>To keep things flexible, we are using both a vertical and horizontal decorator pattern on the <code>ScheduledEmailTaskService</code>. This means that it inherits from <code>EmailTaskService</code> as well as composing in the concrete service itself. But my problem comes from trying to autowire the concrete <code>EmailTaskServiceImpl</code>,  all I get is a <code>No qualifying bean of type EmailTaskServiceImpl</code> exception thrown. Obviously I can't just autowire <code>EmailTaskService</code> because its an abstract class, not an interface.</p>
  
  <p>I'll post the code below to give you an idea of what is going on.<br>
  <b>EmailTaskService</b></p>
  
  <pre><code>public abstract class EmailTaskService&lt;E, I&gt; implements GenericService&lt;E, I&gt;{
  
      @Autowired
      protected EmailTaskDAO emailTaskDao;
  
      public abstract void deleteEmailTask(I emailTaskId);
  </code></pre>
  
  <p>}</p>
  
  <p><b>EmailTaskServiceImpl</b></p>
  
  <pre><code>@Service("emailTaskService")
  public class EmailTaskServiceImpl extends EmailTaskService&lt;EmailTask, Long&gt;{
  
      @Override
      @Transactional
      public long getTotalObjects() {
          return super.emailTaskDao.count();
      }
      etc etc other methods here doing concretey things.
  </code></pre>
  
  <p><b>ScheduledEmailTaskService</b>  </p>
  
  <pre><code>public abstract class ScheduledEmailTaskService&lt;E, I&gt; extends EmailTaskService&lt;E, I&gt; {
  
      @Autowired
      protected ScheduledEmailTaskDAO scheduledEmailTaskDao;
      @Autowired
      @Qualifier("emailTaskService")
      protected EmailTaskService&lt;EmailTask, Long&gt; emailTaskService;
  
      @Override
      public abstract void deleteEmailTask(I emailTaskId) throws InvalidInvocationException;
  
      public abstract void deleteScheduledEmailTask(I scheduledEmailTaskId);
  }
  </code></pre>
  
  <p><b>ScheduledEmailTaskService</b></p>
  
  <pre><code>@Service
  public class ScheduledEmailTaskServiceImpl extends ScheduledEmailTaskService&lt;ScheduledEmailTask, Long&gt; {
  
      @Override
      @Transactional
      public long getTotalObjects() {
          return super.scheduledEmailTaskDao.count();
      }
  
      more concretey methods go here
  </code></pre>
  
  <p>In case you are wondering <code>GenericService&lt;E, I&gt;</code> is an interface that specifies CRUD methods for all my services to implement which is why <code>EmailTaskService</code> implements it.</p>
  
  <p>So my question is how do I get some sort of reference to <code>EmailTaskService</code> or <code>EmailTaskServiceImpl</code> successfully available in <code>ScheduledEmailTaskService</code> either through Autowiring or through another sensible method. If this just isn't possible, Why?</p>
  
  <p>EDIT 1 (Context Configuration):
  Ask and ye shall receive:  </p>
  
  <pre><code>&lt;beans Spring namespace config etc etc etc&gt;
  &lt;context:component-scan base-package="au.com.mail" /&gt;
  
  &lt;mvc:annotation-driven /&gt;
  
  &lt;tx:annotation-driven /&gt;
  
  &lt;task:annotation-driven/&gt;
  
  &lt;!-- Project Properties --&gt;
  &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="locations"&gt;
          &lt;value&gt;classpath:project.properties&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt; 
  &lt;/beans&gt;
  </code></pre>
  
  <p>EDIT 2: Actual Proper Stacktrace:</p>
  
  <pre><code>[junit] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduledEmailTaskServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected au.com.mail.service.emailtask.EmailTaskService au.com.mail.service.emailtask.ScheduledEmailTaskService.emailTaskService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [au.com.mail.service.emailtask.EmailTaskService] 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), @org.springframework.beans.factory.annotation.Qualifier(value=emailTaskService)}
  [junit]     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
  [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
  [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
  [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
  [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
  [junit]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
  [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
  [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  [junit]     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
  [junit]     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  [junit]     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
  [junit]     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
  [junit]     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
  [junit]     at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
  [junit]     at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
  [junit]     at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
  [junit]     at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
  [junit]     ... 50 more
  [junit] Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected au.com.mail.service.emailtask.EmailTaskService au.com.mail.service.emailtask.ScheduledEmailTaskService.emailTaskService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [au.com.mail.service.emailtask.EmailTaskService] 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), @org.springframework.beans.factory.annotation.Qualifier(value=emailTaskService)}
  [junit]     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
  [junit]     at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
  [junit]     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
  [junit]     ... 66 more
  [junit] Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [au.com.mail.service.emailtask.EmailTaskService] 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), @org.springframework.beans.factory.annotation.Qualifier(value=emailTaskService)}
  [junit]     at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988)
  [junit]     at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858)
  [junit]     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
  [junit]     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
  [junit]     ... 68 more
  </code></pre>
  
  <p>And before you ask, yes my JUnit is configured to use the Spring Application Context correctly.</p>