Spring5新特性
注:Spring4.x为Spring4.3.x,Spring5.x为Spring5.2.x
Spring4和Spring5对比
Spring4的全部项目:
Spring5的全部项目:
对比Spring4.x版本和Spring5.x版本可以发现后者多了一个spring-jcl项目,这是Spring自己重写了apache的JCL。
Spring5.x的日志
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.Test;
public class LogTest {
@Test
public void test() {
Log log = LogFactory.getLog(LogTest.class);
System.out.println("这里打印日志");
log.error("------LogTest.......");
}
}
这里的Log和LogFactory并不是apache的,而是Spring自己的。
所以说Spring5中仍然使用JCL,而JCL最终委托Log4j来输出日志。
Spring5的jcl中引入了log4j和slf4j
description = "Spring Commons Logging Bridge"
dependencies {
optional("org.apache.logging.log4j:log4j-api")
optional("org.slf4j:slf4j-api")
}
因此logApi被赋值为LOG4J,接下来便导致创建了一个log4j的log对象:
在打印日志时Log4j会对日志级别判断,默认情况下intLevel的值为200,代表日志级别为ERROR,因此Log4j默认会打印级别高于或等于ERROR的日志。