title: Spring boot Constructor Autowired Exception
body: <p>I have this classes in my spring boot App(spring hibernate/data/jpa/web):</p>
  
  <p>pkg entity:</p>
  
  <pre><code>public interface Base {
  // getter/setter methods
  }
  
  @MappedSuperclass
  public abstract class AbsBase implements Base {
  // common fields &amp; getter/setter methods
  }
  
  @Entity(name = "Config")
  @Table(name = "config")
  public class Config extends AbsBase implements Base, Serializable {
    //additional fields &amp; getter/setter methods
  }
  </code></pre>
  
  <p>pkg repository:</p>
  
  <pre><code>@NoRepositoryBean
  public interface BaseRepository&lt;T extends Base&gt; extends JpaRepository&lt;T, Integer&gt; {}
  
  @Repository
  public interface ConfigRepository extends BaseRepository&lt;Config&gt; {
  //Queries
  }
  </code></pre>
  
  <p>pkg service:</p>
  
  <pre><code>@Transactional
  public interface BaseService&lt;T extends Base&gt; {
  
      @Transactional  void add(T obj);
      @Transactional  void edit(T obj);
      //Etc..
  }
  
  public abstract class AbsBaseService&lt;T extends Base&gt; implements BaseService&lt;T&gt; {
  
      private BaseRepository&lt;T&gt; repository;
  
      public AbsBaseService(BaseRepository&lt;T&gt; repository) {
          super();
          this.repository = repository;
      }
  
      @Override   public void add(T obj) { repository.save(obj); }
      @Override   public void edit(T obj) { repository.save(obj); }
      // Etc
  }
  
  @Service
  public class ConfigService extends AbsBaseService&lt;Config&gt; implements BaseService&lt;Config&gt; {
  
      private ConfigRepository repository;
  
      @Autowired
      public ConfigService(ConfigRepository repository) {
          super(repository);
          this.repository = repository;
      }
      // Etc.
  }
  </code></pre>
  
  <p>If I don't create any Controller all work, but if I create a controller:</p>
  
  <p>pkg controller:</p>
  
  <pre><code>public interface BaseController&lt;T extends Base&gt; { // methods }
  
  public abstract class AbsBaseController&lt;T extends Base&gt; implements BaseController&lt;T&gt; {
  
      private BaseService&lt;T&gt; service;
  
      public AbsBaseController(BaseService&lt;T&gt; service) {
          this.service = service;
      }
  
  @Override
  @RequestMapping(value = "/Add", method = RequestMethod.POST)
  public String addAction(@ModelAttribute("entity") T entity, BindingResult result, Model model,
          final RedirectAttributes redirectAttributes) {
  
      service.add(entity, result);
      if (result.hasErrors()) {
          return addUrl;
      }
  }
  
  @Controller
  public class ConfigController extends AbsBaseController&lt;Config&gt; implements BaseController&lt;Config&gt; {
  
      private ConfigService configService;
  
      @Autowired
      public ConfigController(ConfigService configService) {
          super(configService);
          this.configService = configService;
      }
  }
  </code></pre>
  
  <p>I get this error (error autowired ConfigService in ConfigController):</p>
  
  <pre><code>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configControllerImpl' defined in file [C:\workspace-sts\prueba_boot_thymeleaf\target\classes\prueba\controller\config\ConfigControllerImpl.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [prueba.service.config.ConfigServiceImpl]: No qualifying bean of type [prueba.service.config.ConfigServiceImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [prueba.service.config.ConfigServiceImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
      at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
      at prueba.BootThymeleafApplication.main(BootThymeleafApplication.java:12) [classes/:na]
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [prueba.service.config.ConfigServiceImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
      ... 19 common frames omitted
  </code></pre>
  
  <p>The first question is:
  I have annotated @Transaction the BaseService interface and its methods. It's correct? Better in AbsBaseService class?</p>
  
  <p>I see that configService constructor executes before Exception. 
  Why not Autowired?</p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>I need constructor @Autowired because I implement common methods in abstract/superclass generic service/controller.</p>
  
  <p>The inheritance tree:
  AbsBaseXXXX  -->   AbsBaseCodeNameXXXX  -->   AbsBaseCodeNamePeriodXXXX</p>
  
  <p>Config extends from AbsBase and implements Base.
      ConfigService extends from AbsBaseService&lt;> and implements BaseService&lt;> (use ConfigRepository)
      ConfigController extends from AbsBaseController&lt;> and implements BaseController&lt;> (use ConfigService)</p>
  
  <p>I have a generic abstract classes for common method implementation:
  Interfaces for entity:
      Base, BaseCodeName, BaseCodeNamePeriod....</p>
  
  <ul>
  <li><p>Abstract generic entity class: 
  AbsBase, AbsBaseCodeName, AbsBaseCodeNamePeriod....</p></li>
  <li><p>Generic Interfaces:
  BaseRepository, BaseCodeNameRepository, BaseCodeNamePeriodRepository,...</p></li>
  <li><p>Abstract generic service (That they need corresponding generic repository):
  AbsBaseService, AbsBaseCodeNameService,AbsBaseCodeNamePeriodService,... </p></li>
  <li><p>Abstract generic controller (that they need corresponding generic service):
  AbsBaseController, etc...</p></li>
  </ul>