【Mybatis疑难杂症】ERROR StatusLogger No log4j2 configuration file found. Using default configuration: log

配置log4j找不到配置文件

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

我一开始添加了log4j的core和api没有成功,后发现是core的版本错了,就换成了1的版本

解决步骤

1.mybatisconfig.xml中添加代码

<settings>
                <setting name="logImpl" value="LOG4J"/>
</settings>

2.pom.xml中添加依赖的jar包

<!-- https://mvnrepository.com/artifact/log4j/log4j -->
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.11.1</version>
    </dependency>

3.新建log4j.properties,添加以下代码

# Global logging configuration
log4j.rootLogger=DEBUG, stdout
# MyBatis logging configuration...
log4j.logger.com.cyk.mapper=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

注意第四行的com.cyk.mapper改成你的mapper的路径

4.恭喜完成

猜你喜欢

转载自blog.csdn.net/weixin_43046082/article/details/88930014