springboot +mybatis+maven 整合过程出现的问题及要点

整体的目录结构

项目使用maven 需要引入的核心包

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
</dependency>

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>


<dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
</dependency>
      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
      </dependency>
      <!--引入redies插件-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-redis</artifactId>
   </dependency>
<dependency>
   <groupId>org.mybatis.spring.boot</groupId>
   <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.1</version>
      </dependency>


application.yam文件,配置数据库连接,和mybatis.xml文件加载路径

springboot +mybatis+maven 整合过程出现的问题及要点

如果没有配置标红的部分就会报

Invalid bound statement (not found): com.zhiyou.mapper.UserMapper.insert

找到你mappper接口中的方法,通过配置可以加载到你的mapper.xml  mybatis文件

编写mappper接口时要注意springboot +mybatis+maven 整合过程出现的问题及要点


在UserMapper类中添加@Component(value = "userMapper")和@mapper注解,如果不添加@Component注

在serviceImpl显现类中,注入userMapper接口报错  Could not autowire No beans if 'UserMapper' type found错误,

springboot +mybatis+maven 整合过程出现的问题及要点


相关文章: