INT-4054: Eliminate usage of slf4j

JIRA: https://jira.spring.io/browse/INT-4054
Fixes GH-1833 (https://github.com/spring-projects/spring-integration/issues/1833)

The `DefaultCandidate` pulled requirement for the `slf4j` dependency via its `Logger` and `LoggerFactory` usage.

* Change `slf4j` to the standard Commons Logging
* Exclude `slf4j` transitive dependencies from `optional` direct dependencies like `reactor` and `json-path`
* Since they are `optional` it is safe to exclude their transitives to force our source code to be free from unexpected dependencies.
Anyway they don't appear in the target application as a SI transitives and end-user is forced to pull them manually to switch on the desired features.
If there is need in the `slf4j` for target application, it must be pulled manually as well.

**Cherry-pick to 4.2.x**
This commit is contained in:
Artem Bilan
2016-06-14 15:22:36 -04:00
parent a9b4d206a3
commit fe5ff04489
2 changed files with 21 additions and 7 deletions

View File

@@ -308,9 +308,15 @@ project('spring-integration-core') {
exclude group: 'org.springframework', module: 'spring-core' exclude group: 'org.springframework', module: 'spring-core'
} }
// compile ("org.springframework.cloud:spring-cloud-cluster-core:$springCloudClusterVersion", optional) // compile ("org.springframework.cloud:spring-cloud-cluster-core:$springCloudClusterVersion", optional)
compile ("io.projectreactor:reactor-stream:$reactorVersion", optional) compile ("io.projectreactor:reactor-stream:$reactorVersion") {
optional it
exclude group: 'org.slf4j', module: 'slf4j-api'
}
compile("com.fasterxml.jackson.core:jackson-databind:$jackson2Version", optional) compile("com.fasterxml.jackson.core:jackson-databind:$jackson2Version", optional)
compile("com.jayway.jsonpath:json-path:$jsonpathVersion", optional) compile("com.jayway.jsonpath:json-path:$jsonpathVersion") {
optional it
exclude group: 'org.slf4j', module: 'slf4j-api'
}
compile("io.fastjson:boon:$boonVersion", optional) compile("io.fastjson:boon:$boonVersion", optional)
compile("com.esotericsoftware:kryo-shaded:$kryoShadedVersion", optional) compile("com.esotericsoftware:kryo-shaded:$kryoShadedVersion", optional)

View File

@@ -16,16 +16,20 @@
package org.springframework.integration.leader; package org.springframework.integration.leader;
import org.slf4j.Logger; import org.apache.commons.logging.Log;
import org.slf4j.LoggerFactory; import org.apache.commons.logging.LogFactory;
/** /**
* Simple {@link Candidate} for leadership. * Simple {@link Candidate} for leadership.
* This implementation simply logs when it is elected and when its leadership is revoked. * This implementation simply logs when it is elected and when its leadership is revoked.
*
* @author Janne Valkealahti
* @author Artem Bilan
* @since 4.2
*/ */
public class DefaultCandidate extends AbstractCandidate { public class DefaultCandidate extends AbstractCandidate {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Log logger = LogFactory.getLog(getClass());
private volatile Context leaderContext; private volatile Context leaderContext;
@@ -48,13 +52,17 @@ public class DefaultCandidate extends AbstractCandidate {
@Override @Override
public void onGranted(Context ctx) { public void onGranted(Context ctx) {
this.logger.info("{} has been granted leadership; context: {}", this, ctx); if (this.logger.isInfoEnabled()) {
this.logger.info(this + " has been granted leadership; context: " + ctx);
}
this.leaderContext = ctx; this.leaderContext = ctx;
} }
@Override @Override
public void onRevoked(Context ctx) { public void onRevoked(Context ctx) {
this.logger.info("{} leadership has been revoked", this, ctx); if (this.logger.isInfoEnabled()) {
this.logger.info(this + " leadership has been revoked: " + ctx);
}
} }
/** /**