Skip to content
Advertisement

How to solve “No SLF4J providers were found” when the “slf4j-api” and “slf4j-simple” are already imported?

I am using Guice in a gradle project. When running the main method, I got the following error:

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.

I did some research and added two dependencies in the dependencies section of the build.gradle file as shown below:

dependencies {
    ...
    implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.0-alpha1'
    testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.0-alpha1'
}

But the error is still there…

Do I need to bind the SLF4J provider with something via Guice?

My main method is very simple, so as the AbstractModule class for Guice, as shown below (not sure if they are relevant):

public class Restful {
    public static void main(String[] args) {
        Injector injector = Guice.createInjector(new ApplicationModule());
    }
}

and

public class ApplicationModule extends AbstractModule {
    @Override
    protected void configure() {
        bind(UserDao.class).toInstance(new UserDao());
    }
}

Thank in advance!

Advertisement

Answer

You added slf4j-simple only in test scope, you want it also in runtime scope.

I.e. change testImplementation to implementation in your build definition.


Note that slf4j-simple as the name suggests is a minimal implementation of SLF4J API, you might want to use a more customizable one for production code like logback, log4j2…

User contributions licensed under: CC BY-SA
11 People found this is helpful
Advertisement