【ruoyi-cloud】关于解决使用mybatis-plus框架后启动ruoyi-modules-system报错问题
·
问题描述
使用mybatis-plus框架替换原来的mybatis框架,启动ruoyi系统级应用报错
Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysConfigController': Unsatisfied dependency expressed through field 'configService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysConfigServiceImpl': Unsatisfied dependency expressed through field 'configMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysConfigMapper' defined in file [E:\ruoyi-modules\ruoyi-system\target\classes\com\ruoyi\system\mapper\SysConfigMapper.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 java.io.IOException: Failed to parse mapping resource: 'file [E:\ruoyi-modules\ruoyi-system\target\classes\mapper\system\SysConfigMapper.xml]'
at org.springframework.beans.factory.annotation.Aut
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysConfigServiceImpl': Unsatisfied dependency expressed through field 'configMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sysConfigMapper' defined in file [E:\ruoyi-modules\ruoyi-system\target\classes\com\ruoyi\system\mapper\SysConfigMapper.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 java.io.IOException: Failed to parse mapping resource: 'file [E:\ruoyi-modules\ruoyi-system\target\classes\mapper\system\SysConfigMapper.xml]'
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:713)
at
解决方案:
在nacos里的配置文件没有改,把原来mybatis配置替换为mybatis-plus的:
mybatis-plus:
# mapper映射文件的位置,扫描所有模块下的mapper目录中的XML文件
mapper-locations: classpath*:mapper/**/*.xml
# 实体类的包路径,MyBatis-Plus会在此包下查找实体类并作为别名使用
type-aliases-package: com.ruoyi.**.domain
# MyBatis核心配置
configuration:
# 开启数据库字段下划线命名自动转换为Java实体类的驼峰命名
map-underscore-to-camel-case: true
# 关闭二级缓存(RuoYi框架通常不使用二级缓存)
cache-enabled: false
# 日志实现类,使用标准输出打印SQL语句(开发环境调试用)
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 全局配置
global-config:
db-config:
# 主键生成策略:自动增长(AUTO_INCREMENT)
id-type: auto
# 表名下划线命名(数据库表名使用下划线,与实体类驼峰命名对应)
table-underline: true


魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)