记一次mybatis检查

搭建学习springcloud ,添加数据源,控制台不报错, mybatis无法使用。

1.启动控制台报错: 配置文件未生效

编译后target目录下无mapper.xml和bootstarp.yaml 。   -- 先手动复制进去 。

2.启动成功,调用mybatis出错:

检查mapper.xml 确定没有拼写错误、检查配置文件确定路径正确。

检查ibatis.session.configration

启动类的@MapperScan检查,正确。

configration中查看sqlsessionFactory-》 datasource,正确。 

configration查看mapregistry , 有。 

configration查看mappedstatement ,无!

还是xml 没解析。

 

检查pom文件

   <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>

在单独引入下面依赖后,服务好了
<!-- <dependency>-->
<!-- <groupId>org.mybatis</groupId>-->
<!-- <artifactId>mybatis</artifactId>-->
<!-- <version>3.5.6</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
<!-- <version> 2.7.5 </version>-->
<!-- </dependency>-->

这两个依赖本身存在于mybatis-springboot中。

尝试屏蔽这两个依赖,服务也能正常运行。 检查了个寂寞。。。。

话说为什么没加载resource文件 :
<packaging>pom</packaging> 属性值修改为;<packaging>jar</packaging>



posted @ 2022-11-21 14:24  higsan  阅读(28)  评论(0编辑  收藏  举报