Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

时间:2023-12-22 12:01:38

在使用Springboot 2.0.4 整合Mybatis的时候出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required,然后各种找日志百度,网上给了一种解决方法:

版本太高,使用手动注入sqlSessionFactory,然后用dao的实习类继承,因为我的项目没有dao 的实现类,直接是interface+mapper文件,所以直接忽略了,没有试过,想试一下可以试一下

阅读博客点这里(随手百度的):这里是传送门

    @Resource
public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
super.setSqlSessionFactory(sqlSessionFactory);
}

然后有人说少了mybatis-spring-boot-starter jar包,然后我看的pom.xml文件,没有少

        <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>

坑就出现在这里,因为我用了pagehelper-spring-boot-starter(这是github上一个分页的工具)里面有,和我引入的版本冲突了,把我引入的1.3.2版本的删了,项目就正常启动了,希望可有帮助你们

Springboot 2.0.4 整合Mybatis出现异常Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required