Search code examples
javadependency-injectiondagger

Issue with Dagger: cannot be provided without an @Provides-annotated method


I do have a method annotated w/ @Provides, but somehow it's still failing building with this error:

Router1Component.java:13: error: com.nice.AbcServiceClient cannot be provided without an @Provides-annotated method.

Here's my module:

@Module
public final class Router1Module {

    @Provides
    public AbcServiceClient provideServiceClient() {
        return new ClientBuilder();
    }
}

Here's my interface:

@Singleton
@Component(modules = {Router1Module.class})
public interface Router1Component {
    @LambdaHandler
    Router1Lambda buildRouter1Lambda();
}

Here's my class:

public class Router1Lambda {

    private AbcServiceClient serviceClient;

    @Inject
    public Router1Lambda(
            final AbcServiceClient serviceClient
    ) {
        this.serviceClient = serviceClient;
    }

}

Solution

  • It turned out to be a mix of imports.

    I imported @Provides from GoogleGuice instead of Dagger, that's why Dagger keeps complaining this error...