title: Consider defining a bean of type in your configuration: MyBatis
body: <p>I am new to the whole spring ecosystem. I've been following some tutorials and was able to create a spring boot application and performed crud operations. Then I started changing that project to standards of mybatis.</p>
  <p>I have tried many answers to other similar questions but none are working so far.</p>
  <p>Here is the problem statement:</p>
  <pre><code>//CustomerService.java
  
  package com.crudapp.service;
  
  import com.crudapp.entity.Customer;
  
  import java.util.List;
  
  @Service
  public interface CustomerService {
  
      public List&lt;Customer&gt; getAllCustomers();
  //I have other methods as well to delete, update and post.
  
  }
  </code></pre>
  <p>The implementation class is implemented as:</p>
  <pre><code>
  public class CustomerServiceImpl implements CustomerService {
  
      @Autowired
      private CustomerMapper customerMapper;
  
      @Override
      public List&lt;Customer&gt; getAllCustomers() {
          List&lt;Customer&gt; list = customerMapper.getAllCustomers();
          return list;
      }
  }
  
  </code></pre>
  <p>My Mapper class is like this:</p>
  <pre><code>@Mapper
  public interface CustomerMapper {
  
      public List&lt;Customer&gt; getAllCustomers();
  }
  </code></pre>
  <p>My Mapper.xml class is:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
  &lt;!DOCTYPE mapper PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;  &quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot; &gt;
  &lt;mapper namespace=&quot;com.crudapp.mapper.CustomerMapper&quot;&gt;
      &lt;select id=&quot;getAllCustomers&quot; resultType=&quot;customer&quot;&gt;
          select * from customers
      &lt;/select&gt;
  &lt;/mapper&gt;
  </code></pre>
  <p>and finally my Controller class:</p>
  <pre><code>@RestController
  @RequestMapping(&quot;/api/v1&quot;)
  public class CustomerController {
  
      @Autowired
      CustomerService customerService;
  
      @RequestMapping(value = &quot;/getAllCustomers&quot;, method = RequestMethod.GET)
      public List&lt;Customer&gt; getAllCustomers() {
          List&lt;Customer&gt; list = customerService.getAllCustomers();
          return list;
      }
  }
  </code></pre>
  <p>The error I'm getting is:</p>
  <blockquote>
  <p>Description:</p>
  <p>Field customerMapper in com.crudapp.service.impl.CustomerServiceImpl
  required a bean of type 'com.crudapp.mapper.CustomerMapper' that could
  not be found.</p>
  <p>The injection point has the following annotations:</p>
  <ul>
  <li>@org.springframework.beans.factory.annotation.Autowired(required=true)</li>
  </ul>
  <p>Action:</p>
  <p>Consider defining a bean of type 'com.crudapp.mapper.CustomerMapper'
  in your configuration.</p>
  </blockquote>
  <p>The error is straightforward without a doubt. I think the two @Autowired I have one in the controller the other in service implmentation might be the problem. But my understanding is that the bean will be auto-managed by the framework. So, how would I fix this?</p>
  <p><strong>UPDATE:</strong>
  By adding <code>@MapperScan(&quot;com.crudapp.mapper&quot;)</code> the above error is no longer there but I'm getting this new error:</p>
  <blockquote>
  <p>org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'customerRepo' defined in
  com.crudapp.repository.CustomerRepo defined in
  @EnableJpaRepositories declared on
  JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration:
  Invocation of init method failed; nested exception is
  java.lang.IllegalArgumentException: Not a managed type: class
  com.crudapp.entity.Customer</p>
  </blockquote>
  <p>My main class is:</p>
  <pre><code>@SpringBootApplication
  @MapperScan(&quot;com.crudapp.mapper&quot;)
  public class CrudappApplication {
  
      public static void main(String[] args) {
          SpringApplication.run(CrudappApplication.class, args);
      }
  
  }
  </code></pre>
  <p>In my application.properties file I have:</p>
  <pre><code>mybatis.config=classpath:mapper/mybatis_config.xml
  mybatis.typeAliasesPackage=com.crudapp.entity
  mybatis.mapperLocations=classpath*:**/mappers/*.xml
  </code></pre>
  <p><a href="https://i.stack.imgur.com/NMyKy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NMyKy.png" alt="enter image description here" /></a></p>