Spring boot 整合mybatisPlus 报错“Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required”
1. springboot3.0.3 整合 mybatis-plus3.0.5时,启动报错如下:
Caused by: java.lang.IllegalArgumentException: Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required
2.解决 版本问题。
将 springboot版本下调到3.0.0以下,再次启动,正常。
先前版本
<parent> <groupId>org.springframework.boot</groupId> <version>3.0.3</version> <artifactId>spring-boot-starter-parent</artifactId> </parent>
改为
<parent> <groupId>org.springframework.boot</groupId> <version>2.2.4.RELEASE</version> <artifactId>spring-boot-starter-parent</artifactId> </parent>
网上查到的方法是说SpringBoot 3以后的版本的sqlSessionFactory类代码变红了
如果不是请批评指教。
修改pom.xml文件自动生成的mysql依赖和lombok依赖
可能因为和Spring Boot的版本不匹配,这是个人的配置
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.21</version> </dependency> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</version> </dependency>
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [D:\ideaProject\mybatis_plus\target\classes\com\lrz\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 com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: GlobalConfigUtils setMetaData Fail ! Cause:java.sql.SQLSyntaxErrorException: Unknown database 'mybatis-plus'
看看自己的application.properties文件内是否吧你的URL配错了
此错误因为和自己数据库的mybatis_plus不一样,找了半天错