title: How to fix: Error creating bean with name : Unsatisfied dependency expressed through field in springboot+mybatis
body: <blockquote>
  <p>WARN 12700 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mycontroller': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [D:\Tool\Editor\ideaIu\workplace\toWord\target\classes\com\example\toword\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy</p>
  </blockquote>
  <p><strong>UserController</strong></p>
  <pre><code>@RestController
  public class UserController {
  @Autowired
  private UserService service;
  
  @RequestMapping(&quot;/queryAlluser&quot;)
     public List&lt;User&gt; queryalluser() {
        List&lt;User&gt; list = service.queryAlluser();
        return list;
     }
  }
  </code></pre>
  <p><strong>UserMapper</strong></p>
  <pre><code>@Mapper
  @Component
  public interface UserMapper {
        List&lt;User&gt; queryAlluser();
  }
  </code></pre>
  <p><strong>UerService</strong></p>
  <pre><code>@Service
  public class UserService {
    @Autowired
    private UserMapper userMapper;
    public List&lt;User&gt; queryAlluser(){
      return userMapper.queryAlluser();
    }
  }
  </code></pre>
  <p><strong>UserMapper.xml</strong></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.example.toword.mapper.UserMapper&quot;&gt;
    &lt;select id=&quot;queryAlluser&quot; resultType=&quot;com.example.toword.entity.User&quot;&gt;
       select *
       from user
    &lt;/select&gt;
  &lt;/mapper&gt;
  </code></pre>
  <p>I hava added @MapperScan(basePackages =&quot;com.example.toword.mapper&quot;) in SpringBootApplication.
  And have configurated mapper-location in application.yml as follows.</p>
  <pre><code>mybatis:
    mapper-locations: classpath:com.example.toword.mapper/*.xml
    configuration:
       map-underscore-to-camel-case: true
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DPrFF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DPrFF.png" alt="enter image description here" /></a></p>