Spring boot 整合mybatisPlus 报错

在Springboot3.0.3版本中整合mybatisPlus3.0.5时遇到启动报错,问题根源在于sqlSessionFactory或sqlSessionTemplate未配置。解决方法是将Springboot版本回退至3.0.0以下,如2.2.4.RELEASE,同时检查数据库连接配置,确保URL正确无误。错误也可能是由于不同库的版本不兼容导致。
摘要由CSDN通过智能技术生成

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不一样,找了半天错

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值