springboot 高版本后继续使用log4j的解决方法
来源:互联网 发布:世界局势知乎 编辑:程序博客网 时间:2024/06/05 09:53
springboot 高版本后不支持log4j了,很多人还是喜欢log4j风格的日志,我们自己来加载log4j,其实很容易。
第一步:我们手动加入我们想要的log4j jar,在项目里面随便建一个文件夹,将用到的jar丢进去,右键 add to build path
第二步:
在main函数启动类所在的包或者其子包下写一个这样的类,用来加载log4j配置文件,是的,什么内容都没有。
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@ConfigurationProperties("classpath:log4j.properties")
public class Log4jConfigure {
}
这里可能会出现黄色警告提示你要在pom文件中,加入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
如下依赖,你点击确定,他自动帮你加上了。
第二步:将log4j.properties文件丢到application.properties配置文件旁边就可以了,其他什么事情都不用做,
controller中用法和以前一模一样,
import com.dome.dao.UserMapper;
import com.entity.User;
@RestController
@RequestMapping({"/home"})
public class UserController {
private static Logger log = Logger.getLogger(UserController.class);
log.debug("debug加载默认用户成功");
log.info("加载默认用户成功");
log.error("遇到错误,回滚成功")
}
接下来我们我们配置mybatis的日志输出设置为log4j
在application.properties旁边添加一个mybatis-config.xml文件,填入如下内容
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
</configuration>
接着打开application.properties,添加如下一行信息,SQL语句就能输出到控制台了
mybatis.config-location=classpath:mybatis-config.xml
- springboot 高版本后继续使用log4j的解决方法
- SpringBoot 中使用 Log4j
- SpringBoot 中使用 Log4j
- SpringBoot中使用 Log4j
- SpringBoot使用log4j
- MSDN订阅用户使用Download Manager下载大文件中断后继续下载的解决方法
- Application Loader 上传中断后无法继续上传的解决方法
- Log4j和Log4j2的区别(SpringBoot中配置使用)
- $HTTP_RAW_POST_DATA的高版本使用
- 使用高版本boost库导致xp下找不到GetTickCount64函数的解决方法
- 使用高版本boost库导致xp下找不到GetTickCount64函数的解决方法
- 高德地图 AMap3DMap_4.0导航功能 在5.0以上版本无法使用的解决方法
- 高版本chrome安装flashplayer debuger后无法使用的问题
- xcode升级后ios9.0不能使用http协议的版本的解决方法介绍
- 杂谈,以及HttpClient过时后,继续使用HttpClient的方法
- SmartGit(试用期30后),个人继续使用的方法。
- SmartGit(试用期30后),个人继续使用的方法。
- SmartGit(试用期30后),个人继续使用的方法
- Python的hasattr() getattr() setattr() 函数使用方法详解
- MySQL之备份与恢复
- 解决npm err windows_nt 6.1.7601问题
- Window10磁盘分区
- ORACLE 12C新特性——CDB与PDB
- springboot 高版本后继续使用log4j的解决方法
- (待完善)Ubuntu 16.04下1080Ti显卡的安装方式
- 标准库类型string
- 17ICPC南宁 G I 计算几何+暴力
- case/casez/casex
- 使用Python3将manifest.xml转为excel供查看
- Android Studio-Didn't find class XXX on path: DexPathList [zip file "/data/app/packagename/base.apk]
- LeetCode 23:Merge k Sorted Lists 解题与思考
- 西瓜书读书笔记(一)