common-logging
在springframework的spring-core中强制指定了使用common-logging模块,该模块是标准的实现至Jarka Common Log(JCL)的,并在runtime运行时自动发现其它框架选择的日志组件,并定位一个认为最接近的日志组件作为应用日志(如果什么都没找到,会使用JDK的LOG,(java.util.logging or JUL for short)),在maven中只需要配置了spring-core就有了
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
</dependencies>
SLF4J
使用SLF4J(Simple Log Factory For JAVA)需要将common-logging排除,同时需要使用SL4J桥接,将springframework的common-logging桥接到SL4J上,所以需要4个依赖,同时排除spring-core中自带的common-logging,使用maven如下
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
log4j
使用log4j时不需要排除spring-core中的common-logging,同时log4j也是运行时绑定,相当于common-logging在运行时绑定了log4j,maven如下
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>