title: Unable to autowire dozer Mapper in component class in spring boot
body: <p>I am new to <em>Spring Boot</em>. I was trying to develop small application in <em>spring boot</em> mvc with <em>neo4j</em> database. Following is my <em>Server</em></p>
  <pre><code>@Configuration
  @ComponentScan({ &quot;myproject&quot; })
  @EnableAutoConfiguration
  @EnableNeo4jRepositories(basePackages = &quot;myproject&quot;)
  public class Server extends Neo4jConfiguration implements CommandLineRunner
  {
  
  public Server()
  {
      setBasePackage(&quot;myproject&quot;);
  }
  
  @Bean
  SpringRestGraphDatabase graphDatabaseService()
  {
      return new SpringRestGraphDatabase(&quot;http://localhost:7474/db/data&quot;);
  }
  
  @Bean
  Mapper mapper()
  {
      return new DozerBeanMapper();
  }
  
  public void run(String... args) throws Exception
  {
  }
  
  public static void main(String[] args) throws Exception
  {
      SpringApplication.run(Server.class, args);
  }
  
  }
  </code></pre>
  <p>Following is my main class</p>
  <pre><code>@Configuration
  @ComponentScan({ &quot;myproject.business&quot; })
  @EnableNeo4jRepositories(basePackages = &quot;myproject&quot;)
  public class MainWithStructure extends Neo4jConfiguration implements CommandLineRunner
  {
  @Autowired
  private MyService myService;
  
  public MainWithStructure()
  {
      setBasePackage(&quot;myproject&quot;);
  }
  
  @Bean
  SpringRestGraphDatabase graphDatabaseService()
  {
      return new SpringRestGraphDatabase(&quot;http://localhost:7474/db/data&quot;);
  }
  
  .......
  ......
  public static void main(String[] args) throws Exception
  {
      FileUtils.deleteRecursively(new File(&quot;accessingdataneo4j.db&quot;));
  
      SpringApplication app = new SpringApplication(MainWithStructure.class);
      app.setWebEnvironment(false);
      app.run(args);
  }
  
  }
  </code></pre>
  <p>Following is my <em>Component</em> class</p>
  <pre><code>@Component
  public class MyService
  {
  
  @Autowired
  private Mapper mapper;  //Fails to autowire org.dozer.Mapper
  
  .....
  }
  </code></pre>
  <p>Following is my <em>Controller</em> class</p>
  <pre><code>@RestController
  @RequestMapping(&quot;/rest&quot;)
  public class MyController
  {
  @Autowired
  private Mapper mapper;  //autowire sucess org.dozer.Mapper
  }
  </code></pre>
  <p>I got following Exception when I run main class <em>MainWithStructure</em></p>
  <blockquote>
  <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mainWithStructure': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private myproject.business.MyService myproject.main.MainWithStructure.MyService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.dozer.Mapper myproject.business.MyService.mapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.dozer.Mapper] 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)}</p>
  </blockquote>
  <p>Following is my project structure</p>
  <blockquote>
  <p>demo_project</p>
  <ul>
  <li>src/main/java</li>
  </ul>
  <p>---myproject.main</p>
  <p>------MainWithStructure.java</p>
  <p>------Server.java</p>
  <p>---myproject.business</p>
  <p>------MyService.java</p>
  <p>---myproject.rest</p>
  <p>------MyController.java</p>
  </blockquote>
  <p>If I autowire <code>org.dozer.Mapper</code> in <em>Controller</em>, it sucessfuly autowired it. BUT if I autowire <code>org.dozer.Mapper</code> in <em>Component</em> class it fails to autowire.
  Why it is failing to autowire <code>org.dozer.Mapper</code> only on Component class?</p>
  <p>Please make me correct if I wrong. Thank you :)</p>