From bdcb9407eb36c76f01a952082cf2c46c10d6f25a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 28 May 2014 23:00:29 +0100 Subject: [PATCH] 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 --- ...gurationReportLoggingInitializerTests.java | 30 +++++-------------- spring-boot-cli/pom.xml | 17 ++++------- spring-boot-dependencies/pom.xml | 12 ++++---- spring-boot-parent/pom.xml | 11 ++----- .../spring-boot-loader-tools/.gitignore | 1 + spring-boot/pom.xml | 9 +++--- 6 files changed, 28 insertions(+), 52 deletions(-) create mode 100644 spring-boot-tools/spring-boot-loader-tools/.gitignore diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java index 1e75c595db..26f738fbd3 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/logging/AutoConfigurationReportLoggingInitializerTests.java @@ -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 infoLog = new ArrayList(); - 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)) { diff --git a/spring-boot-cli/pom.xml b/spring-boot-cli/pom.xml index cc14ef193e..e9e3ddfb0c 100644 --- a/spring-boot-cli/pom.xml +++ b/spring-boot-cli/pom.xml @@ -104,22 +104,17 @@ org.eclipse.aether aether-transport-http + + + jcl-over-slf4j + org.slf4j + + org.eclipse.aether aether-util - - org.slf4j - jcl-over-slf4j - - - - org.slf4j - slf4j-nop - 1.7.7 - runtime - org.codehaus.groovy diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index a31d44b742..c2edd05218 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -429,6 +429,12 @@ org.apache.httpcomponents httpasyncclient ${httpasyncclient.version} + + + commons-logging + commons-logging + + org.apache.tomcat.embed @@ -825,12 +831,6 @@ org.springframework spring-core ${spring.version} - - - commons-logging - commons-logging - - org.springframework diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index b771b93849..3d6059ea3d 100644 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -230,7 +230,7 @@ false - + @@ -367,15 +367,10 @@ - 1.7 + (1.7,) - - - commons-logging:commons-logging:*:compile - - true - + true diff --git a/spring-boot-tools/spring-boot-loader-tools/.gitignore b/spring-boot-tools/spring-boot-loader-tools/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/spring-boot-tools/spring-boot-loader-tools/.gitignore @@ -0,0 +1 @@ +/target diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index 2206a2bcae..47d1717e77 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -20,10 +20,6 @@ - - org.slf4j - jcl-over-slf4j - org.springframework spring-core @@ -154,6 +150,11 @@ spring-webmvc test + + org.slf4j + jcl-over-slf4j + test +