SpringBoot升级到3.3.2版本,JDK升级到17,引入Mybatis-plus后启动报错:Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
【问题描述】
2024-07-23T15:16:07.174+08:00 WARN 2604 --- [questionnaire] [ main] ConfigServletWebServerApplicationContext :
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'TActivitySessionServiceImpl': Unsatisfied dependency expressed through field 'baseMapper':
Error creating bean with name 'TActivitySessionMapper' defined in file [D:\xxx\yyy\target\classes\com\xxx\yyy\zzz\mapper\TxxxMapper.class]:
Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
2024-07-23T15:16:07.176+08:00 INFO 2604 --- [questionnaire] [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2024-07-23T15:16:07.206+08:00 INFO 2604 --- [questionnaire] [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-07-23T15:16:07.225+08:00 ERROR 2604 --- [questionnaire] [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'TActivitySessionServiceImpl': Unsatisfied dependency expressed through field 'baseMapper': Error creating bean with name 'TActivitySessionMapper' defined in file [D:\xxx\yyy\target\classes\com\xxx\xxx\yyy\mapper\TxxxMapper.class]: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
【原因分析】
SpringBoot2.x版本和JDK8没有这个问题,当SpringBoot升级到3.3.2版本,JDK升级到17版本,再引入Mybatis-plus后就会启动报错,不能自动加载sqlSessionFactory。
【解决方案】
需要升级mybatis-plus的坐标依赖:
由:mybatis-plus-boot-starter
<!--<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.7</version>
</dependency>-->
修改为:mybatis-plus-spring-boot3-starter
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.5</version>
</dependency>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具