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

@ -104,22 +104,17 @@
<dependency> <dependency>
<groupId>org.eclipse.aether</groupId> <groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId> <artifactId>aether-transport-http</artifactId>
<exclusions>
<exclusion>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.aether</groupId> <groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId> <artifactId>aether-util</artifactId>
</dependency> </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 --> <!-- Provided -->
<dependency> <dependency>
<groupId>org.codehaus.groovy</groupId> <groupId>org.codehaus.groovy</groupId>

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

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

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

Loading…
Cancel
Save