Restore commons-logging dependency for spring-boot

Restore the dependency on commons-logging (transitively via spring-core)
for spring-boot. This means that we are not tied directly to SLF4J, but
it is still an option that can be used via `jcl-over-slf4j`.

The `spring-boot-starter-parent` continues to replace `commons-logging`
with `jcl-over-slf4j`.

Fixes gh-981
pull/1016/head
Phillip Webb 11 years ago
parent 5a5a7be477
commit bdcb9407eb

@ -16,15 +16,14 @@
package org.springframework.boot.autoconfigure.logging;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogConfigurationException;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.commons.logging.impl.NoOpLog;
import org.apache.commons.logging.impl.SLF4JLogFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -42,7 +41,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.mock.web.MockServletContext;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import static org.hamcrest.Matchers.containsString;
@ -73,10 +71,6 @@ public class AutoConfigurationReportLoggingInitializerTests {
protected List<String> infoLog = new ArrayList<String>();
private Field logFactoryField;
private LogFactory originalLogFactory;
@Before
public void setup() {
setupLogging(true, true);
@ -104,25 +98,15 @@ public class AutoConfigurationReportLoggingInitializerTests {
}
}).given(this.log).info(anyObject());
try {
this.logFactoryField = LogFactory.class.getDeclaredField("logFactory");
ReflectionUtils.makeAccessible(this.logFactoryField);
this.originalLogFactory = (LogFactory) ReflectionUtils.getField(
this.logFactoryField, null);
ReflectionUtils.setField(this.logFactoryField, null, new MockLogFactory());
}
catch (Exception ex) {
throw new IllegalStateException("Failed to set logFactory", ex);
}
LogFactory.releaseAll();
System.setProperty(LogFactory.FACTORY_PROPERTY, MockLogFactory.class.getName());
this.initializer = new AutoConfigurationReportLoggingInitializer();
}
@After
public void cleanup() {
ReflectionUtils.setField(this.logFactoryField, null, this.originalLogFactory);
System.clearProperty(LogFactory.FACTORY_PROPERTIES);
LogFactory.releaseAll();
}
@Test
@ -215,7 +199,7 @@ public class AutoConfigurationReportLoggingInitializerTests {
containsString("Unable to provide auto-configuration report"));
}
public static class MockLogFactory extends SLF4JLogFactory {
public static class MockLogFactory extends LogFactoryImpl {
@Override
public Log getInstance(String name) throws LogConfigurationException {
if (AutoConfigurationReportLoggingInitializer.class.getName().equals(name)) {

@ -104,22 +104,17 @@
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<exclusions>
<exclusion>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<!-- Runtime -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.7</version>
<scope>runtime</scope>
</dependency>
<!-- Provided -->
<dependency>
<groupId>org.codehaus.groovy</groupId>

@ -429,6 +429,12 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>${httpasyncclient.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
@ -825,12 +831,6 @@
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>

@ -367,15 +367,10 @@
<configuration>
<rules>
<requireJavaVersion>
<version>1.7</version>
<version>(1.7,)</version>
</requireJavaVersion>
<bannedDependencies>
<excludes>
<exclude>commons-logging:commons-logging:*:compile</exclude>
</excludes>
<searchTransitive>true</searchTransitive>
</bannedDependencies>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>

@ -20,10 +20,6 @@
</properties>
<dependencies>
<!-- Compile -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
@ -154,6 +150,11 @@
<artifactId>spring-webmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

Loading…
Cancel
Save