Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Spring Data force dependency on SLF4j?

The Spring docs explicitly mention that spring only depends on on commons-logging. However, if i add a dependency to Spring Data MongoDb, gradle adds a dependency on slf4j.

org.springframework.data:spring-data-commons:1.5.1.RELEASE       
+--- org.springframework:spring-core:3.1.4.RELEASE (*)           
+--- org.springframework:spring-beans:3.1.4.RELEASE (*)          
+--- org.slf4j:slf4j-api:1.7.1                                   
\--- org.slf4j:jcl-over-slf4j:1.7.1

Does this mean I am forced to use SLF4j if i use spring data?

like image 323
pdeva Avatar asked May 25 '13 19:05

pdeva


3 Answers

Yes, we have a compile time dependency on the Slf4j API as it's the de-facto standard logging API for Java and the one causing the least hassle of all the options available: JUL - I better don't leave a word on this one (see this one if you still need to be convinced), Commons Logging - runtime provider detection has proven a PITA.

We additionally require jcl-over-slf4j to provide a Commons Logging implementation to satisfy the Commons Logging dependency of the core Spring framework, a dependency it has to maintain for legacy reasons but would have not been introduced in the first place if Slf4j had been available back in the days.

So, yes. We're setting incentives to do the "right thing" (tm), read: "the way the Java community has agreed on at large". If you really want to stick to Commons Logging, simply add the slf4j-jcl bridge and you're set. If you want to remove the jcl-over-slf4j bridge, simply exclude the dependency.

like image 151
Oliver Drotbohm Avatar answered Oct 30 '22 04:10

Oliver Drotbohm


You can disable SLF4J logging in Spring Data by adding to pom.xml:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring-data-jpa.version}</version>
        <!-- Exclude slf4j logging in favor of log4j -->
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>${commons-logging.version}</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
    </dependency>
like image 3
szaroblekitny Avatar answered Oct 30 '22 03:10

szaroblekitny


SLF4J is only a Logging Facade that in spring case will delegate in commons logging, using the jcl-over-slf4j dependency.

If you want your app to use commons-logging you can simply exclude slf4j dependencies.

like image 2
genjosanzo Avatar answered Oct 30 '22 04:10

genjosanzo