Lets say I have binded my strings in guice like this
bind(String.class).annotatedWith(MasterDatabase.class).toInstance("integration");
If I have the handler to injector
for this module, how would I get back the value binded through the annotation name? Here I wanted the string value associated with MasterDatabase
annotation
Well you'd normally use constructor injection using the annotation:
@Inject
public SomeType(@MasterDatabase String databaseName)
Or you could explicitly request it from the injector:
String databaseName = injector.getInstance(Key.get(String.class,
MasterDatabase.class));
See more on this question at Stackoverflow