Код первым:Guice @Provides работать с дополнительным Nullable инъекции не работает
@Slf4j
public class HelperModule extends AbstractModule
{
@Override
protected void configure()
{
}
@Provides
@Named("plugin")
@Singleton
public Reflections getReflections(@Nullable @Named("plugin-scope") String pluginScope)
{
if (pluginScope == null)
{
pluginScope = "me.wener";
}
log.info("Create plugin scanner for '{}'", pluginScope);
return new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage(pluginScope))
.addScanners(
new SubTypesScanner(),
new TypeAnnotationsScanner())
// .filterInputsBy(new FilterBuilder().include(".*\\.java").exclude(".*"))
);
}
}
Что я ожидал это pluginScope
может быть пустым и не обязательно, я следовать инструкции Use @Nullable, но это не работает, я до сих пор получил
No implementation for java.lang.String annotated with @com.google.inject.name.Named(value=plugin-scope) was bound
Что случилось?
EDIT BTW, The @Nullable
является javax.annotation.Nullable
Как насчет '@Inject (optional = true)'? –
@MilanBaran пытался, еще не wrks – wener