title: No qualifying bean of type - Kotlin Spring boot
body: <p>I'm learning Kotlin - Spring boot and <code>CrudRepository</code> aren't working in my project.</p>
  
  <p>I used all annotations (<code>@Repository</code>, <code>@Component</code>, <code>@ComponentScan</code> in MainApplication.kt)</p>
  
  <p>Now I need help with this <code>AutoWired</code> problem and <em>Repository not found</em> error.</p>
  
  <p>here is <strong>WorkerService.kt</strong></p>
  
  <pre><code>
      import org.springframework.beans.factory.annotation.Autowired
      import org.springframework.stereotype.Service
  
      @Service
      class WorkerService constructor(@Autowired private val workerRepository: WorkerRepository,
                                      @Autowired private val projectRepository: ProjectRepository) {
  
          fun getWorkers(): ArrayList&lt;Worker&gt; {
              val workers: ArrayList&lt;Worker&gt; = workerRepository.findAll()
              return workers
          }
  
          fun getWorker(id: Long): Worker {
              val worker = workerRepository.findById(id)
              val projects = projectRepository.findAllByProjectId(id)
              worker.setProjects(projects)
              return worker
          }
  
          fun addWorker(worker: Worker): Worker {
              return workerRepository.save(worker)
          }
      }
  </code></pre>
  
  <p>and here is <strong>ProjectRepository.kt</strong></p>
  
  <pre><code>    import org.springframework.data.repository.CrudRepository
  
      interface ProjectRepository : CrudRepository&lt;Project, Long&gt; { //
          fun findAllByProjectId(projectId: Long): ArrayList&lt;Project&gt;
      }
  </code></pre>
  
  <p>and error messages received</p>
  
  <pre><code>    java.lang.IllegalStateException: Failed to load ApplicationContext
  
          at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
          at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:123)
          at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190)
          at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132)
          at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:244)
          at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:98)
          at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassBasedTestDescriptor.java:337)
          at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.executeAndMaskThrowable(ClassBasedTestDescriptor.java:342)
          at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassBasedTestDescriptor.java:337)
          at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
          at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
          at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
          at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
          at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
          at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
          at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:743)
          at java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:742)
          at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
          at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestInstancePostProcessors(ClassBasedTestDescriptor.java:336)
          at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:259)
          at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$2(ClassBasedTestDescriptor.java:252)
          at java.util.Optional.orElseGet(Optional.java:267)
          at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$3(ClassBasedTestDescriptor.java:251)
          at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:29)
          at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$prepare$0(TestMethodTestDescriptor.java:106)
          at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
          at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:105)
          at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.prepare(TestMethodTestDescriptor.java:69)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$prepare$1(NodeTestTask.java:107)
          at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.prepare(NodeTestTask.java:107)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:75)
          at java.util.ArrayList.forEach(ArrayList.java:1257)
          at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
          at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
          at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
          at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
          at java.util.ArrayList.forEach(ArrayList.java:1257)
          at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
          at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
          at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
          at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
          at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
          at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
          at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
          at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
          at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
          at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
          at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
          at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
          at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
          at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
          at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
          at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
          at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
      Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'workerService' defined in file [D:\IJProjects\nins\nins-api\build\classes\kotlin\main\com\tistory\fonercis\nins\application\WorkerService.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tistory.fonercis.nins.domain.ProjectRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
          at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
          at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
          at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
          at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
          at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
          at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
          at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:125)
          at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
          at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
          ... 63 more
      Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.tistory.fonercis.nins.domain.ProjectRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1695)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1253)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
          at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885)
          at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789)
          ... 81 more
  </code></pre>