栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Mybatis添加依赖后产生错误 org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Mybatis添加依赖后产生错误 org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration.

Mybatis添加依赖后产生错误:org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis/mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.logging.LogException: Error setting Log implementation. Cause: java.lang.reflect.InvocationTargetExceptionlog4j引发的错误

目录
  • 问题复现
  • 产生原因及解决
    • 深究原因:
  • 附:SpringBoot运行报错:

问题复现

mybatis配置添加日志后


    

maven中的Dependencies会有红色波浪线:log4j:log4j:unknown

查看了一下pom.xml中关于log4j的依赖


    log4j
    log4j
    compile

产生原因及解决

其中没有写版本号,查阅资料后发现:

因为:
log4j自1.2.17版本以后,就改变jar包了
比如:1.2.17及以前的版本的mvn依赖是这样写的:


    log4j
    log4j
    1.2.17


然而1.2.17以后的版本的mvn依赖是这样写的:


    org.apache.logging.log4j
    log4j-core
    2.13.1

于是,按第一种方法显示的声明使用1.2.17版本,问题解决。

之后想要通过修改pom中依赖的设置再复现问题发现复现不了,我猜测的原因是maven已经处理好了相关的依赖,需要maven clean操作

深究原因:

我们知道SpringBoot中的依赖不用写版本号是因为其自动版本仲裁机制,我们点击项目的父项目


    org.springframework.boot
    spring-boot-starter-parent
    2.5.4
     

ctrl加左键点击spring-boot-starter-parent,发现这个项目还有父项目spring-boot-dependencies


  org.springframework.boot
  spring-boot-dependencies
  2.5.4

进入spring-boot-dependencies后可以看到里面声明了开发过程中常用的jar包的版本号和依赖

我们搜索log4j后看到结果是

2.14.1

看起来和我们之前找到的原因相同。

附:SpringBoot运行报错:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookController': Unsatisfied dependency expressed through field 'bookService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookService': Unsatisfied dependency expressed through field 'bookMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookMapper' defined in file [D:tsgltargetclassescombytsglmapperBookMapper.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 [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.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 org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis/mybatis-config.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.logging.LogException: Error setting Log implementation. Cause: java.lang.reflect.InvocationTargetException

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/425451.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号