Guice @Inject class 来自 jar - 没有实现被绑定

Guice @Inject class from jar - No implementation was bound

我有 Maven 项目,它使用另一个项目作为 jar 库。我有来自 jar 的 @Inject'ed UserService 接口,我得到:

com.google.inject.ConfigurationException:Guice 配置错误: 1) 没有绑定 UserService 的实现。

我尝试将 UserService 接口绑定到具体的 class,但后来我得到 "No implementation for ... was bound" 注入到 UserService 中的 class 异常。如何解决这个问题?


public class UserServiceImpl 实现 UserService

@Override
protected void configure() {
    Properties configProperties = loadPropertiesFile("device.properties");
    bind(Properties.class).annotatedWith(AppProperties.class).toInstance(configProperties);

    Names.bindProperties(binder(), configProperties);
    Names.bindProperties(binder(), loadProperties("/" + GenericBootstrapConstants.BOOTSTRAP_PROPERTIES_FILE));

    bind(UserService.class).to(UserServiceImpl.class);
}

我为每个注入的服务设置了 bind() 和 addMapperClasses()。谢谢 Jérémie B