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
This commit is contained in:
Phillip Webb
2014-05-28 23:00:29 +01:00
parent 5a5a7be477
commit bdcb9407eb
6 changed files with 28 additions and 52 deletions

View File

@@ -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;
@@ -58,7 +56,7 @@ import static org.mockito.Mockito.mock;
/**
* Tests for {@link AutoConfigurationReportLoggingInitializer}.
*
*
* @author Phillip Webb
*/
public class AutoConfigurationReportLoggingInitializerTests {
@@ -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)) {